FileZilla Server从1.0版本开始,FTPS默认会强制采用TLS_RESUME。采用Python的FTP_TLS模块的话,需要自己继承一个子类,并进行修改实现TLS_RESUME, 并skip掉SSLSocket的unwrap。
#If you met the problem of 450 TLS session of data connection has not resumed or the session does not match the control connection
#I met this problem on filezilla server, it is because python FTP_TLS can't support resume session
#there is a workaround to solve this problem
#reference: https://stackoverflow.com/questions/46633536/getting-a-oserror-when-trying-to-list-ftp-directories-in-python
class ReusedSslSocket(SSLSocket):
def unwrap(self):
pass
#MyFTP_TLS is derieved to support TLS_RESUME(filezilla server)
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.