when I implement python to download large quantities of data from ftp, I appear
ftplib.error_temp: 425 Can"t open passive connection: Address already in use
to confirm that no other transmission tools occupy the connection. The port defaults to 21. How can I avoid this problem?
-Code-
class ftpmgr:
def __init__(self,host, username, password, upload_root, download_root, remoteroot):
self.host = host
self.username = username
self.password = password
self.download_root = download_root
self.upload_root = upload_root
self.remoteroot = remoteroot
self.ftp = FTP()
def connect(self):
self.ftp.connect(self.host, 21)
self.ftp.login(self.username, self.password)
def downloadfile(self, localpath, remotepath):
bufsize = 1024
fp = open(localpath, "wb")
self.ftp.retrbinary("RETR " + remotepath, fp.write, bufsize)
self.ftp.set_debuglevel(0)
fp.close()
-sharp picpath_listsql
def download(self,picpath_list):
self.connect()
-sharp self.ftp.cwd(self.remoteroot)
for remotefile in picpath_list:
relpath = "/".join(remotefile.split("/")[-4:])
localfile = os.path.join(self.download_root,relpath)
self.downloadfile(localfile, remotefile)
print "%s Downloads" % relpath
self.ftp.quit()
-error message-