-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.py
More file actions
39 lines (37 loc) · 1.52 KB
/
Copy pathclient.py
File metadata and controls
39 lines (37 loc) · 1.52 KB
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
import sys
import zmq
import transfer
import config
user_id = sys.argv[1]
master_ip = config.master_ip
context = zmq.Context()
socket = context.socket(zmq.REQ)
for i in range(config.number_of_masters):
socket.connect("tcp://{}:{}".format(master_ip, config.master_start_port + i))
command = input().split(" ")
while command[0] != "quit":
operation = command[0]
filename = command[1]
if operation == "upload":
socket.send_string("upload")
response = socket.recv_json()
if response is None:
print("404: All ports are busy. Try again later :D")
else:
print("Uploading to {}:{}".format(response[0], response[1]))
transfer.upload_to_server(filename, user_id, context, response[0], response[1])
print('"{}" uploaded successfully'.format(filename))
elif operation == "download":
socket.send_string("download {}".format(filename))
response = socket.recv_json()
if response is None:
print("File not found")
elif len(response[0]) == 0:
print("All ports are busy")
else:
keepers = ", ".join(["{}:{}".format(ip, port) for ip, port in zip(response[0], response[1])])
print("Downloading from {}".format(keepers))
transfer.download_from_servers(filename, context, response[0], response[1], response[2])
print('"{}" downloaded successfully'.format(filename))
command = input().split(" ")
# transfer.upload_to_server("file.mp4", context, "127.0.0.1", 5556)