发生EOF违反了Python ftplib协议的情况 [英] EOF occurred in violation of protocol with Python ftplib
问题描述
我正在使用Python ftplib开发隐式TLS连接程序.我尝试了有问题的解决方案 python-ftp-implicit-tls-connection-issue (包括Rg Glpj和Juan Moreno的答案)建立连接.但是当我这样登录ftp服务器后调用 retrline
或 retrbinary
时( FTP_ITLS
是 FTP_TLS
的子类):
I'm working on an implicit TLS connection program with Python ftplib. I tried the solution provided in question python-ftp-implicit-tls-connection-issue(including Rg Glpj's and Juan Moreno's answers) to make the connection. But when I call retrline
or retrbinary
after logging into the ftp server like this(FTP_ITLS
is the subclass of FTP_TLS
):
58 server = FTP_ITLS()
59 server.connect(host="x.x.x.x", port=990)
60 server.login(user="user", passwd="******")
61 server.prot_p()
62
63 server.cwd("doc")
64 print(server.retrlines('LIST'))
65 # server.retrbinary('RETR contents.7z', open('contents.7z', 'wb').write)
66 server.quit()
我遇到EOF错误:
Traceback (most recent call last):
File "D:/Coding/test/itls.py", line 64, in <module>
print(server.retrlines('LIST'))
File "D:\Python\Python27\lib\ftplib.py", line 735, in retrlines
conn = self.transfercmd(cmd)
File "D:\Python\Python27\lib\ftplib.py", line 376, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "D:\Python\Python27\lib\ftplib.py", line 713, in ntransfercmd
server_hostname=self.host)
File "D:\Python\Python27\lib\ssl.py", line 352, in wrap_socket
_context=self)
File "D:\Python\Python27\lib\ssl.py", line 579, in __init__
self.do_handshake()
File "D:\Python\Python27\lib\ssl.py", line 808, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:590)
似乎ftplib使用 PROTOCOL_SSLv23
作为Python 2.7中的默认协议,我尝试了PROTOCOL_TLSv1,PROTOCOL_TLSv1_1和PROTOCOL_TLSv1_2,但是它们都不起作用.我还尝试覆盖 ntransfercmd
和 auth
,或设置 ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1)
,如Steffen Ullrich在问题中所说的
As it seems ftplib uses PROTOCOL_SSLv23
as the default protocol in Python 2.7, I tried
PROTOCOL_TLSv1, PROTOCOL_TLSv1_1 and PROTOCOL_TLSv1_2, but none of them worked. And I also tried overriding ntransfercmd
and auth
, or setting ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1)
as Steffen Ullrich said in question connect-to-ftp-tls-1-2-server-with-ftplib, but the error never disappeared. What can I do then? Thanks.
推荐答案
我在尝试连接FileZilla FTP服务器时遇到了这种情况.FileZilla在基于TLS的FTP设置" 中有一个设置,称为"",在使用PROT P时要求在数据连接上恢复TLS会话".禁用此选项可以解决此问题.
I ran into this trying to connect to a FileZilla FTP server. FileZilla has a setting in the "FTP over TLS settings" called "Require TLS session resumption on data connection when using PROT P". Disabling this option fixed this problem.
如果您无法控制服务器,请查看带有Python ftplib的FTPS-需要会话重用讨论了如何启用会话重用.不过,这似乎需要Python 3.6 +.
If you don't have control over the server, check out FTPS with Python ftplib - Session reuse required which goes over how to enable session reuse. This seems to require Python 3.6+, however.
这篇关于发生EOF违反了Python ftplib协议的情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!