简体   繁体   English

在python中使用ftplib时

[英]when using ftplib in python

Here is the relevant code that's causing the Error. 以下是导致错误的相关代码。

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

I've never seen this error before and any information about why I might be getting it would be useful and appreciated. 我之前从未见过这个错误,任何关于我为什么会得到它的信息都会有用和赞赏。

complete error message: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 完整错误消息:[Errno 10060]连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应

It should be noted that when I manually (ie open a dos-prompt and push the files using ftp commands) push the file from the same machine that the script is on, I have no problems. 应该注意的是,当我手动(即打开dos提示并使用ftp命令推送文件)从脚本所在的同一台机器推送文件时,我没有问题。

也许你应该增加“ 超时 ”选项,让服务器有更多的时间来响应。

就我而言,正如@Anders Lindahl建议的那样,改用ACTV模式,让一切恢复正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM