when using ftplib in python

时光怂恿深爱的人放手 提交于 2020-01-03 15:24:47

问题


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

It should be noted that when I manually (i.e. 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.


回答1:


Maybe you should increase the "timeout" option, and let the server more time to response.




回答2:


In my case, changing to ACTV mode, as @Anders Lindahl suggested, got everything back into working order.



来源:https://stackoverflow.com/questions/4946960/when-using-ftplib-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!