我正在使用python ftplib进行隐式tls连接程序.我尝试了有问题的解决方案python-ftp-implicit-tls-connection-issue(包括Rg Glpj和Juan Moreno的答案)来建立连接.但是当我打电话retrline或retrbinary登录到这样的ftp服务器后(FTP_ITLS是子类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()
Run Code Online (Sandbox Code Playgroud)
我收到了一个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)
Run Code Online (Sandbox Code Playgroud)
由于看起来ftplib PROTOCOL_SSLv23在Python 2.7中用作默认协议,我尝试了PROTOCOL_TLSv1,PROTOCOL_TLSv1_1和PROTOCOL_TLSv1_2,但它们都没有工作.我也尝试重写ntransfercmd和auth,或设置ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1)为斯特芬·乌尔里希在提问时说连接到FTP-TLS-1-2-服务器与-FTPLIB,但误差不会消失.那我该怎么办?谢谢.
小智 7
我在尝试连接到 FileZilla FTP 服务器时遇到了这个问题。FileZilla 在“FTP over TLS 设置”中有一个设置,称为“使用 PROT P 时需要在数据连接上恢复 TLS 会话”。禁用此选项解决了此问题。
如果您无法控制服务器,请查看FTPS with Python ftplib - 需要会话重用,其中介绍了如何启用会话重用。然而,这似乎需要 Python 3.6+。
| 归档时间: |
|
| 查看次数: |
993 次 |
| 最近记录: |