Python - download all folders, subfolders, and files with the python ftplib module -


i have been working day trying figure out how use python ftplib module download folders, subfolders, , files ftp server come this.

from ftplib import ftp import sys, ftplib  sys.tracebacklimit = 0 # not display traceback errors sys.stderr = "/dev/null" # not display attribute errors  host = "ftp.debian.org" port = 21 username = "" password = ""  def mainclass():     global ftp     global con     host     port     ftp = ftp()     con = ftp.connect(host, port) # connects host specified port  def grabfile():     source = "/debian/"     filename = "readme.html"     ftp.cwd(source)     localfile = open(filename, 'wb')     ftp.retrbinary('retr ' + filename, localfile.write)     ftp.quit()     localfile.close()  try:     mainclass() except exception:     print "not connected"     print "check address", host + ":" + str(port) else:     print "connected"  if ftplib.error_perm , not username == "" , password == "":     print "please check credentials\n", username, "\n", password  credentials = ftp.login(username, password) grabfile() 

this python script download readme.html file ftp.debian.org but, able download whole folders files , subfolders in them , cannot seem figure out. have searched around different python scripts using module cannot seem find want.

any suggestions or appreciated.

note: still use python job different module such ftputil or other 1 out there.

thanks in advance, alex

the short solution: possibly run: "wget -r ftp://username:password@ftp.debian.org/debian/*" files under debian directory. can process files in python.

the long solution: can go on every directory listing using ftplib, getting directory listing parsing , getting every file , recursing directories. if search web you'd find previous posts on stackoverlow solve issue


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -