Pracuję na niejawny program połączenia tls z Pythona ftplib. Próbowałem rozwiązania podanego w pytaniu python-ftp-implicit-tls-connection-issue (w tym odpowiedzi Rg Glpj i Juana Moreno), aby nawiązać połączenie. Ale gdy zgłoszę retrline
lub retrbinary
po zalogowaniu się na serwerze ftp tak (FTP_ITLS
jest podklasą FTP_TLS
):EOF wystąpił z naruszeniem protokołu z python ftplib
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()
mam błąd 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)
Jak się wydaje ftplib wykorzystuje PROTOCOL_SSLv23
jako domyślny protokół w Pythonie 2.7 wypróbowałem PROTOCOL_TLSv1, PROTOCOL_TLSv1_1 i PROTOCOL_TLSv1_2, ale żaden z nich nie zadziałał. Próbowałem także przesłonić ntransfercmd
i auth
lub ustawić ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1)
jako Steffen Ullrich powiedział w pytaniu connect-to-ftp-tls-1-2-server-with-ftplib, ale błąd nigdy nie zniknął. Co mogę wtedy zrobić? Dzięki.