-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
sendScript.py
52 lines (43 loc) · 1.45 KB
/
sendScript.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
#!/usr/bin/env python3
import socket, os, sys, struct
def send(file, ip):
host = ip
port = 34567
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
s.sendall(struct.pack('i', os.fstat(file.fileno()).st_size))
input("Press enter to send data")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
data = file.read()
s.sendall(data)
def sendName(name, ip):
host = ip
port = 34567
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
s.sendall(struct.pack('i', len(name.encode())))
input("Press enter to send the filename")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
s.sendall(name.encode())
def main(args):
filename = ""
ip = ""
argCount = len(args)
if argCount == 1:
filename = input("Please enter the filename of the script to send: ")
ip = input("Please enter PKSM's IP: ")
elif argCount == 2:
filename = args[1]
ip = input("Please enter PKSM's IP: ")
elif argCount == 3:
filename = args[1]
ip = args[2]
with open(filename,'rb') as f:
# send filename without subdirectories
sendName(os.path.basename(filename), ip)
input("name sent, press enter to send script")
send(f, ip)
if __name__ == '__main__':
main(sys.argv)