我在Python 2.7.3中遇到FTP_TLS(ftplib)问题。
调查结果摘要(通过互联网进行的所有连接尝试):
以下代码显示了我如何重现该问题。连接到我的家庭服务器时,此代码在我的个人FTP上生成与FileZilla相同的日志。 (仅当连接到GoDaddy站点时才会导致EOF异常。)
from ftplib import FTP_TLS
o = FTP_TLS(ftpServer,ftpUsername,ftpPassword,ftpPort)
o.voidcmd('SYST')
o.voidcmd('FEAT')
o.prot_p()
o.voidcmd('PWD')
o.retrbinary('MLSD', open('OUTTEST', 'wb').write)
>>> o.retrbinary('MLSD', open('OUTTEST', 'wb').write)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/ftplib.py", line 703, in retrbinary
return self.voidresp()
File "/usr/lib/python2.7/ftplib.py", line 225, in voidresp
resp = self.getresp()
File "/usr/lib/python2.7/ftplib.py", line 211, in getresp
resp = self.getmultiline()
File "/usr/lib/python2.7/ftplib.py", line 197, in getmultiline
line = self.getline()
File "/usr/lib/python2.7/ftplib.py", line 187, in getline
if not line: raise EOFError
我读到服务器关闭管道时给出了EOF错误。它也类似于如果你改为prot_p然后尝试发出一个纯文本命令会发生什么(虽然据我所知,这不是这里的情况)。
我不明白我的代码和FileZilla之间有什么不同。所有尝试都通过互联网进行的事实让我确信它与防火墙无关。此外,FileZilla可以工作,所以从技术角度来看,连接是可能的,我只是很难用Python实现它。
如果我没有发出prot_p开关,我的代码可以与GoDaddy FTP一起使用。
其他信息:
运行我的代码后的典型FileZilla服务器日志。
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> Connected on port 21, sending welcome message...
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> 220-FileZilla Server 0.9.57 beta
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> 220-written by Tim Kosse (Tim.Kosse@gmx.de)
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> 220 Please visit https://filezilla-project.org/
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> AUTH TLS
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> 234 Using authentication type TLS
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> SSL connection established
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> USER ********************
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> 331 Password required for USER_NAME
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> PASS ********************
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 230 Logged on
(000131)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> disconnected.
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> SYST
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 215 UNIX emulated by FileZilla
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> FEAT
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 211-Features:
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> MDTM
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> REST STREAM
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> SIZE
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> MODE Z
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> MLST type*;size*;modify*;
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> MLSD
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> AUTH SSL
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> AUTH TLS
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> PROT
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> PBSZ
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> UTF8
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> CLNT
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> MFMT
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> EPSV
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> EPRT
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 211 End
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> PBSZ 0
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 200 PBSZ=0
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> PROT P
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 200 Protection level set to P
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> PWD
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 257 "/" is current directory.
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> TYPE I
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> 200 Type set to I
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> PASV
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> 227 Entering Passive Mode (xxx,xxx,xxx,xxx,xxx,xxx)
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> MLSD
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> 150 Opening data channel for directory listing of "/"
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> SSL connection for data connection established
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> 226 Successfully transferred "/"
答案 0 :(得分:1)
当我发现时,出现此问题是因为GoDaddy FTP服务器坚持要求FTP会话恢复。这真的很痛苦,但我可以原谅他们,因为这是一个必要的安全功能。
目前,Python3并不支持开箱即用的SSL会话恢复(尽管你会注意到自2.7以来已经添加了SSLContext,所以我认为它会来。https://docs.python.org/3/library/ssl.html#ssl.SSLContext)。< / p>
此处有一个关于此问题的错误帖子:https://bugs.python.org/issue19500
答案 1 :(得分:0)
我认为你需要将FTP模式设置为被动模式,这里是similar error but in Perl
中解释