将文件上传到FTP时出错 - (ftplib.error_reply:226传输完成。传输0个字节.0 bps。)

时间:2018-05-28 10:08:58

标签: python-3.x ftplib

我正在尝试在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.

注意到的典型行为是,在前几次运行中,这种方法运行良好,但随后开始抛出错误。

0 个答案:

没有答案