Skip to content

Instantly share code, notes, and snippets.

@cmc333333
Created August 7, 2014 16:33
Show Gist options
  • Select an option

  • Save cmc333333/9619f67d550a4b70e2ad to your computer and use it in GitHub Desktop.

Select an option

Save cmc333333/9619f67d550a4b70e2ad to your computer and use it in GitHub Desktop.
Quick ftp download all
∴ 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