在python中使用ftplib时

Ram*_*amy 5 python ftplib

以下是导致错误的相关代码.

ftp = ftplib.FTP('server')
ftp.login(r'user', r'pass')

#change directories to the "incoming" folder
ftp.cwd('incoming')

fileObj = open(fromDirectory + os.sep + f, 'rb')

#push the file
try:
    msg = ftp.storbinary('STOR %s' % f, fileObj)
except Exception as inst:
    msg = inst
finally:
    fileObj.close()
    if '226' not in msg:
    #handle error case
Run Code Online (Sandbox Code Playgroud)

我之前从未见过这个错误,任何关于我为什么会得到它的信息都会有用和赞赏.

完整错误消息:[Errno 10060]连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应

应该注意的是,当我手动(即打开dos提示并使用ftp命令推送文件)从脚本所在的同一台机器推送文件时,我没有问题.

Ram*_*amy 1

就我而言,按照 @Anders Lindahl 的建议,更改为 ACTV 模式,让一切恢复正常工作。