-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclnt.py
51 lines (43 loc) · 1.08 KB
/
clnt.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
43
44
45
46
47
48
49
50
51
import socket
import sys
import time
no_files = len(sys.argv)-1
s = socket.socket()
host = ""
port = 60001
s.connect((host, port))
s.send(str(no_files))
time.sleep(0.01)
file_names = []
for i in range(no_files):
file_name = './Data/' + sys.argv[i+1]
file_names.append(file_name)
s.send(file_name)
time.sleep(0.01)
file_sizes = []
for i in range(no_files):
size = s.recv(1024)
file_sizes.append(int(size))
time.sleep(0.01)
for i in range(no_files):
#status = s.recv(1024)
if file_sizes[i] == -1:
print("Sorry! The file was not found!")
continue
time.sleep(0.5)
size = 0
with open(sys.argv[i+1], 'wb') as f:
while True:
print('Downloading data...')
data = s.recv(1024)
size = size + len(data)
time.sleep(0.1)
if size == file_sizes[i]:
f.write(data)
print("File has been downloaded successfully")
break
f.write(data)
#print("Yeay! File has been downloaded...")
#f.close()
s.close()
print('connection closed')