FTPES - Session Reuse Required

So, I'm trying to connect to the ftp server to get directories and upload files. But the first command after the prot_p () function throws an exception. The output of these errors from the log:

*get* '150 Here comes the directory listing.\r\n'
*resp* '150 Here comes the directory listing.'
*get* '522 SSL connection failed; session reuse required: see require_ssl_reuse
option in vsftpd.conf man page\r\n'
*resp* '522 SSL connection failed; session reuse required: see require_ssl_reuse
 option in vsftpd.conf man page'
Traceback (most recent call last):
  File "C:\temp\download.py", line 29, in <module>
    files = ftps.dir()
  File "C:\Python27\lib\ftplib.py", line 522, in dir
    self.retrlines(cmd, func)
  File "C:\Python27\lib\ftplib.py", line 725, in retrlines
    return self.voidresp()
  File "C:\Python27\lib\ftplib.py", line 224, in voidresp
    resp = self.getresp()
  File "C:\Python27\lib\ftplib.py", line 219, in getresp
    raise error_perm, resp
ftplib.error_perm: 522 SSL connection failed; session reuse required: see requir
e_ssl_reuse option in vsftpd.conf man page

Here is the code:

from ftplib import FTP_TLS
import os
import socket

host = 'example.com'
port = 34567
user = 'user1'
passwd = 'pass123'
acct = 'Normal'

ftps = FTP_TLS()

ftps.set_debuglevel(2)

ftps.connect(host, port)

print(ftps.getwelcome())
print(ftps.sock)

ftps.auth()

ftps.login(user, passwd, acct)

ftps.set_pasv(True)
ftps.prot_p()

print('Current directory:')
print(ftps.pwd())
files = ftps.dir()

ftps.quit()

I want to do this safely, therefore, using FTP through TLS Explicit. I have an idea that I might need to manipulate some of the settings in the Socket class referenced by FTPLib. Changing the settings on the server is not possible. I successfully tested the server with the FileZilla client, an older version of WinSCP raised the same error - although updating to the latest version fixed it.

Any ideas?

+5
source share
2 answers

, vsftpd, ftplib, , .

, FTP_TLS , , -, HACK, SO FTP TLS Python. python 19500:

" , TLS.
. , " 522 "
.

. , , TLS, ".

, vsftpd , " SSL ".

http://scarybeastsecurity.blogspot.com/2009/02/vsftpd-210-released.html

Python ftplib.py, SSL ( , . FTP_TLS.transfercmd(cmd [, rest]) ¶, ).

FTP-, FTPS, .. WinSCP: https://winscp.net/tracker/668

. . vsftpd "require_ssl_reuse" true vsftpd.conf, .

, .

+5

Python 3.6 + ( FTP_TLS):

class MyFTP_TLS(ftplib.FTP_TLS):
    """Explicit FTPS, with shared TLS session"""
    def ntransfercmd(self, cmd, rest=None):
        conn, size = ftplib.FTP.ntransfercmd(self, cmd, rest)
        if self._prot_p:
            conn = self.context.wrap_socket(conn,
                                            server_hostname=self.host,
                                            session=self.sock.session)  # this is the fix
        return conn, size
+4

All Articles