EOF occurred in violation of protocol with python ftplib

I am working on an implicit tls connection program with ftplib python. I tried the solution presented under python-ftp-implicit-tls-connection-issue (including Rg Glpj and Juan Moreno answers) to establish a connection. But when I call retrline or retrbinary after entering ftp server like this ( FTP_ITLS is a subclass of FTP_TLS ):

 58 server = FTP_ITLS() 59 server.connect(host="xxxx", 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() 

I got an EOF error:

 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) 

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 to override ntransfercmd and auth or set ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1) , as Steffen Ulrich said with the question connect-to-ftp-tls-1-2-server-with-ftplib , but the error never disappeared . What can I do then? Thanks.

+5
source share
1 answer

I came across this while trying to connect to a FileZilla FTP server. FileZilla has an option in the settings for โ€œFTP over TLSโ€ called โ€œRequire a TLS session to resume when connecting to data when using PROT Pโ€. Disabling this option fixed the problem.

If you do not have control over the server, check FTPES - Session Reuse , which describes how to enable session reuse. However, this seems to require Python 3.6+.

0
source

Source: https://habr.com/ru/post/1237554/


All Articles