Python FTP下载-仅从FTP下载16个文件,而不是从FTP下载所有文件?
大家好。我在下载python ftp时遇到了一个问题。每次我运行这个脚本并连接到我的ftp站点时,它只下载16个文件,其中ftp站点包含近数百个文件,而且还在增加,因为它每天都会更新和添加文件。我想知道是因为互联网连接,还是脚本中缺少了一些东西,使我能够下载所有我真的无法理解的文件。如有任何帮助/建议/意见,我们将不胜感激。谢谢!
以下是脚本:(其中一些来自这里
Http://code.activestate.com/recipes/...on-ftp-client/
)
选择 | 换行 | 行号
- from ftplib import FTP
- import os, sys, os.path, operator
- import wx
- host_name = raw_input("Enter your FTP Site: ")
- if "http://" in host_name:
- host_name = host_name.replace("http://","")
- host_name = host_name.replace("\n","")
- user = raw_input("Enter username: ")
- pwd = raw_input("Enter password: ")
- try: ftph = FTP(host_name)
- except:
- print "Host could not be resolved."
- raw_input()
- sys.exit()
- else: pass
- try:
- ftph.login(user,pwd)
- except Exception:
- if user == "anonymous" or user == "Anonymous" and pwd == "anonymous" or pwd == "Anonymous":
- print "The server does not accept anonymous requests."
- raw_input()
- sys.exit()
- else:
- print "Invalid login combination."
- raw_input()
- sys.exit()
- else:
- print "Successfully connected!\n"
- print ftph.getwelcome()
- flag = 1
- count = 0
- path = ftph.pwd()
- charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
- def handleDownload(block):
- file.write(block)
- print ".",
- ddir='#localdirectory'
- os.chdir(ddir)
- ftp = FTP('#yourftpsite')
- print 'Logged in!'
- ftp.login('', '')
- directory = '#ftpdirectory'
- print 'Changing to ' + directory
- ftp.cwd(directory)
- ftp.retrlines('LIST')
- print 'Downloading files...'
- filenames = []
- ftp.retrlines('NLST', filenames.append)
- print filenames
- for filename in filenames:
- local_filename = os.path.join('#localdirectory', filename)
- file = open(local_filename, 'wb')
- ftp.retrbinary('RETR '+ filename, file.write)
- file.close()
- ftp.close()