-
Notifications
You must be signed in to change notification settings - Fork 2
/
sendfile.py
45 lines (34 loc) · 893 Bytes
/
sendfile.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
#!/usr/bin/env Python
import sys
import ftplib
import datetime
from ftplib import FTP
# Usage:
# sendfile.py "filename" "ftppath" "host" "ip"
def printf(string):
print(datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') + " : " + string);
if __name__ == '__main__':
print("");
printf("FTP File Sender\n")
try:
filename = sys.argv[1]
path = sys.argv[2]
host = sys.argv[3]
port = sys.argv[4]
ftp = FTP()
printf("Connecting to " + host + ":" + port);
ftp.connect(host, port);
printf("Connected");
printf("Opening " + filename);
file = open(sys.argv[1], "rb");
printf("Success");
printf("Moving to: ftp:/" + path);
ftp.cwd(path);
printf("Sending file");
ftp.storbinary('STOR '+ filename, file);
printf("Done")
file.close();
ftp.quit();
printf("Disconnected");
except IOError as e:
printf("/!\ An error occured. /!\ ");