我试图连接到FTP,但我无法运行任何命令。在
ftp_server = ip
ftp_username = username
ftp_password = password
ftp = ftplib.FTP(ftp_server)
ftp.login(ftp_username, ftp_password)
'230 Logged on'
ftp.nlst()
ftp.nlst
引发此错误:
Error:
[WinError 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
我用FileZilla(在同一台机器上运行)测试了连接,它工作得很好。在
这是FileZilla日志:
^{pr2}$
以上说明FTP服务器配置错误。它将其内部网络IP发送到外部网络(到客户端-FileZilla或Python ftplib),在那里它是无效的。FileZilla可以检测到这一点并自动返回到服务器的原始IP地址。在
pythonftplib不执行这种检测。在
您需要修复FTP服务器以返回正确的IP地址。在
如果无法修复服务器(它不是您的服务器,而且管理员不合作),您可以通过重写
FTP.makepasv
使ftplib忽略返回的(无效的)IP地址并使用原始地址:相关问题 更多 >
编程相关推荐