【发布时间】:2016-03-11 20:54:17
【问题描述】:
我正在使用 Python ftplib 开发一个隐式 TLS 连接程序。我尝试了问题python-ftp-implicit-tls-connection-issue(包括Rg Glpj 和Juan Moreno 的答案)提供的解决方案来建立连接。但是当我像这样登录ftp服务器后调用retrline或retrbinary时(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, 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 在connect-to-ftp-tls-1-2-server-with-ftplib 中所说的那样,但错误从未消失。那我能做什么呢?谢谢。
【问题讨论】:
标签: python python-2.7 ftp ftplib