-
Notifications
You must be signed in to change notification settings - Fork 7
/
client_try1.py
executable file
·42 lines (36 loc) · 1.29 KB
/
client_try1.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
32
33
34
35
36
37
38
39
40
41
42
import socket
import time
def Main():
host = '10.0.0.11'
port = 8765
s = socket.socket()
s.connect((host, port))
filename = raw_input("Filename? -> ")
file_ext=filename.split('.')[-1]
if filename != 'q':
s.send(filename)
data = s.recv(1024)
if data[:6] == 'EXISTS':
filesize = long(data[6:])
message = raw_input("File exists, " + str(filesize) +"Bytes, download? (Y/N)? -> ")
if message.upper() == 'Y':
s.send("OK")
startTime = s.recv(1024)
f = open('new_file_from_client'+file_ext, 'wb')
data = s.recv(1024)
totalRecv = len(data)
f.write(data)
while totalRecv < filesize:
data = s.recv(1024)
totalRecv += len(data)
f.write(data)
print "{0:.2f}".format((totalRecv/float(filesize))*100)+ "% Done"
endTime = time.time()
print endTime - float(startTime)
print "Download Complete!"
f.close()
else:
print "File Does Not Exist!"
s.close()
if __name__ == '__main__':
Main()