forked from mc-17/pspack-flask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sender.py
31 lines (27 loc) · 906 Bytes
/
sender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import socket
from bcolors import bcolors,printColor
def send(ip, port, file):
clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, proto=0)
clientSocket.settimeout(3000)
print(('try sending "' + file +'" to "' + ip + ':' + str(port) + '"'))
# print(port)
# print (file)
try:
clientSocket.connect((ip, port))
with open(file, "rb") as fp:
clientSocket.sendfile(fp)
clientSocket.close()
except Exception as inst:
# print(type(inst)) # the exception instance
# print(inst.args) # arguments stored in .args
# print(inst)
if(inst.args[1]):
printColor(bcolors.ERROR,inst.args[1])
return inst.args[1]
else:
print("error")
return "Unknown error"
else:
return "You're all set!"
finally:
clientSocket.close()