-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetLatestFTP.py
More file actions
executable file
·47 lines (40 loc) · 1.05 KB
/
Copy pathgetLatestFTP.py
File metadata and controls
executable file
·47 lines (40 loc) · 1.05 KB
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
#!/usr/bin/env python
import ftplib
import os
import socket
HOST = 'ftp.mozilla.org'
DIRN = 'pub/mozilla.org/webtools'
FILE = 'bugzilla-LATEST.tar.gz'
def main():
try:
f = ftplib.FTP(HOST)
except (socket.error, socket.gaierror), 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.cwd(DIRN)
except ftplib.error_perm:
print 'ERROR: cannot CD to "%s" folder' % DIRN
f.quit()
return
print '*** Changed to "%s" folder' % DIRN
try:
f.retrbinary('RETR %s' % FILE,
open(FILE, 'wb').write)
except ftplib.error_perm:
print 'ERROR: cannot read file "%s"' % FILE
if os.path.exists(FILE): os.unlink(FILE)
else:
print '*** Downloaded "%s" to CWD' % FILE
f.quit()
return
if __name__ == '__main__':
main()