您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – FTPES – 需要会话重用

5b51 2022/1/14 8:22:56 python 字数 3481 阅读 591 来源 www.jb51.cc/python

所以,我正在尝试连接到ftp服务器以获取目录列表和下载文件.但是prot_p()函数之后的第一个命令引发了异常 – 从日志中产生这些错误: *get* '150 Here comes the directory listing.\r\n' *resp* '150 Here comes the directory listing.' *get* '522 SSL connection failed;

概述

*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

这是代码

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()

我想安全地这样做,因此使用FTP over TLS Explicit.我有一个想法,我可能需要操作FTPLib引用的Socket类中的一些设置.不可能更改服务器上的设置.我已经使用FileZilla客户端成功测试了服务器,旧版本的WinSCP引发了同样的错误 – 尽管升级到最新版本修复了它.

有任何想法吗?

class MyFTP_TLS(ftplib.FTP_TLS):
    """Explicit FTPS,with shared TLS session"""
    def ntransfercmd(self,cmd,rest=None):
        conn,size = ftplib.FTP.ntransfercmd(self,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

总结

以上是编程之家为你收集整理的python – FTPES – 需要会话重用全部内容,希望文章能够帮你解决python – FTPES – 需要会话重用所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶