我正在使用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()
我收到了一个EOF错误:
Traceback (most recent call last): File "D:/Coding/test/itls.py", line 64, inprint(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)
为斯特芬·乌尔里希在提问时说连接到FTP-TLS-1-2-服务器与-FTPLIB,但误差不会消失.那我该怎么办?谢谢.