-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetFTP.py
36 lines (30 loc) · 813 Bytes
/
getFTP.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
import ftplib
import os
import socket
HOST = 'ftp.mozilla.org'
DIRN = 'pub/mozilla.org/webtolls'
FILE = 'bugzilla-LATEST.tar.gz'
def main():
try:
f = ftplib.FTP(HOST)
except (socket.error, socket.gaierror) as e:
print('ERROR: cannot reach "%s"' % HOST)
return
print('*** Connected to host"%s"' % HOST)
try:
f.login()
except ftplib.error_perm:
print('ERROR: cannot login anonymously')
f.quit()
return
print('*** Logged in as "anonymous"')
try:
f.retrbinary('RETR %s' % FILE, open(FILE, 'wb').write)
except ftplib.error_perm:
print('ERROR: cannot read file "%s"' % FILE)
os.unlink(FILE)
else:
print('*** Download "%s" wo CWD' % FILE)
f.quit()
if __name__ == '__main__':
main()