我正在尝试在FTP位置上传多个文件。代码工作得非常好,但现在已经开始抛出错误了。
使用的代码:
import ftplib
ftp = ftplib.FTP("ftp.com")
ftp.login('ID', 'PWD')
ftp.cwd("/dir")# ftp directory
fileList=[list] # A dynamic list of pdf files to be uploaded.
for i in fileList:
filename=i+'.pdf'
print(filename)
with open('C:\myfilespath\' + filename,'rb') as f_upload:
ftp.storbinary('STOR ' + filename,f_upload)
ftp.quit()
ftp.close()
收到错误:
Traceback (most recent call last):
File "C:/mypath.py", line 13, in <module>
ftp.storbinary('STOR ' + filename,f_upload)
File "C:\mypath\Lib\ftplib.py", line 502, in storbinary
with self.transfercmd(cmd, rest) as conn:
File "C:\mypath\Lib\ftplib.py", line 397, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "C:\\mypath\Lib\ftplib.py", line 357, in ntransfercmd
host, port = self.makepasv()
File "C:\\mypath\Lib\ftplib.py", line 335, in makepasv
host, port = parse227(self.sendcmd('PASV'))
File "C:\\mypath\Lib\ftplib.py", line 843, in parse227
raise error_reply(resp)
ftplib.error_reply: 226 Transfer complete. 0 bytes transferred. 0 bps.
注意到的典型行为是,在前几次运行中,这种方法运行良好,但随后开始抛出错误。