-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslave.py
73 lines (63 loc) · 1.92 KB
/
slave.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#command list
# view_cwd --> will show all files in directory where the file is running
# custom_dir --> will show files from custom directory
# download_file --> will download files from directory
import os
import socket
s = socket.socket()
port = 8080
host = input(str("Please enter the server address: "))
s.connect((host,port))
print("")
print("Connected to server sucessfully")
print("")
#connection has been completed
#command receiving and execution
while 1:
command = s.recv(1024)
command = command.decode()
print("Command recieved")
print("")
if command == "view_cwd":
files = os.getcwd()
files = str(files)
s.send(files.encode())
print("")
print("Command has been executed successfully..")
print("")
elif command == "custom_dir":
user_input = s.recv(5000)
user_input = user_input.decode()
files = os.listdir(user_input)
files = str(files)
s.send(files.encode())
print("")
print("Command has been executed successfully..")
print("")
elif command == "download_file":
file_path = s.recv(5000)
file_path = file_path.decode()
file = open(file_path,"rb")
data = file.read()
s.send(data)
print("")
print("File has been sent sucessfully")
print("")
elif command == "remove_file":
fileandir = s.recv(6000)
fileanddir = fileandir.decode()
os.remove(fileanddir)
print("")
print("Command has been executed sucessfully")
print("")
elif command == "send_file":
filename= s.recv(6000)
print(filename)
new_file = open(filename,"wb")
data=s.recv(6000)
print(data)
new_file.write(data)
new_file.close()
else:
print("")
print("Command not recognized.")