Python FTP_TLS之FileZilla Server -TLS RESUME踩坑425错误

本文介绍了在使用Python FTP_TLS模块与FileZilla Server交互时遇到的425错误,该错误发生在使用storbinary上传文件时。通过分析,发现可能原因是服务器端对TLS连接关闭方式的特殊处理。为解决此问题,作者通过继承FTP_TLS并修改storbinary函数,实现了正常关闭连接。虽然会出现客户端超时异常,但捕获并忽略该异常后,文件上传成功且服务器端无异常信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值