我编写了一些代码来登录到一个 AS/400 FTP 站点,移动到某个目录,并找到我需要下载的文件。它有效,但似乎有很多文件要下载时我收到:
socket.error: [Errno 10054] An existing connection was
forcibly closed by the remote host
我登录并成功导航到相应的目录:
try:
newSession = ftplib.FTP(URL,username,password)
newSession.set_debuglevel(3)
newSession.cwd("SOME DIRECTORY")
except ftplib.all_errors, e:
print str(e).split(None,1)
sys.exit(0)
我获取了我需要的文件列表:
filesToDownload= filter(lambda x: "SOME_FILE_PREFIX" in x, newSession.nlst())
这就是它正在死去的地方(特别是newSession.retrbinary('RETR '+f,tempFileVar.write)
):
for f in filesToDownload:
newLocalFileName = f + ".edi"
newLocalFilePath = os.path.join(directory,newLocalFileName)
tempFileVar = open(newLocalFilePath,'wb')
newSession.retrbinary('RETR '+f,tempFileVar.write)
tempFileVar.close()
它在我被击中之前下载了我需要的文件的 85% 以上,Errno 10054
我想我只是对为什么它在如此接近完成时似乎任意死亡感到困惑。我现在诚实的猜测是尝试提取这些文件时对 FTP 的请求太多。
这是出现在我的命令提示符上的错误截图:
任何建议或指示都会很棒。我仍在尝试解决此问题。