Created
August 7, 2014 16:33
-
-
Save cmc333333/9619f67d550a4b70e2ad to your computer and use it in GitHub Desktop.
Quick ftp download all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ∴ cat ftpall.py | |
| from ftplib import FTP | |
| import sys | |
| from urlparse import urlparse | |
| if len(sys.argv) == 1: | |
| print "Usage: python ftpall.py ftp://path/to/dir" | |
| exit(1) | |
| url = urlparse(sys.argv[1]) | |
| ftp = FTP(url.netloc) | |
| ftp.login() | |
| ftp.cwd(url.path) | |
| filenames = [] | |
| def dir_list(line): | |
| filenames.append(line[56:]) | |
| ftp.dir(dir_list) | |
| for filename in filenames: | |
| writing_to = open(filename, 'wb') | |
| ftp.retrbinary('RETR ' + filename, writing_to.write) | |
| writing_to.close() | |
| print "Downloaded", filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment