forked from brandon-rhodes/fopnp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryul.py
More file actions
executable file
·26 lines (21 loc) · 762 Bytes
/
binaryul.py
File metadata and controls
executable file
·26 lines (21 loc) · 762 Bytes
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
#!/usr/bin/env python3
# Foundations of Python Network Programming, Third Edition
# https://github.com/brandon-rhodes/fopnp/blob/m/py3/chapter17/binaryul.py
from ftplib import FTP
import sys, getpass, os.path
def main():
if len(sys.argv) != 5:
print("usage:", sys.argv[0],
"<host> <username> <localfile> <remotedir>")
exit(2)
host, username, localfile, remotedir = sys.argv[1:]
prompt = "Enter password for {} on {}: ".format(username, host)
password = getpass.getpass(prompt)
ftp = FTP(host)
ftp.login(username, password)
ftp.cwd(remotedir)
with open(localfile, 'rb') as f:
ftp.storbinary('STOR %s' % os.path.basename(localfile), f)
ftp.quit()
if __name__ == '__main__':
main()