【问题标题】:FTPHost.walk in ftputil connected to FTPS server not returning anythingftputil 中的 FTPHost.walk 连接到 FTPS 服务器不返回任何内容
【发布时间】:2021-06-18 23:17:22
【问题描述】:

我正在尝试使用 ftputil 的 walk 方法获取 FTP 站点目录下的文件和路径列表:

import ftputil
from ftplib import FTP_TLS

host = 'my_host'
user = 'my_user'
pw = 'my_pw'
folder = '/my/dir'

ftp = ftputil.FTPHost(host, user, pw, session_factory=FTP_TLS)

for root,dirs,files in ftp.walk(folder):
    print(root, dirs, files)

但是,没有打印任何内容。 ftp.walk(folder) 确实返回了一个生成器对象,但没有生成任何内容。我错过了什么?也许我没有正确处理 TLS 连接(尽管我没有收到任何错误)?

【问题讨论】:

    标签: python ftp ftplib ftps


    【解决方案1】:

    我需要运行 prot_p 作为设置会话的一部分:

    class TLSFTPSession(FTP_TLS):
    
        def __init__(self, host, userid, password):
            FTP_TLS.__init__(self)
            #self.set_debuglevel(2)
            self.connect(host, 21)
            self.login(userid, password)
            self.prot_p()
    
    ftp = ftputil.FTPHost(host, user, pw, session_factory=TLSFTPSession)
    

    然后就可以了!

    【讨论】:

      猜你喜欢
      • 2011-10-14
      • 1970-01-01
      • 2023-03-15
      • 2016-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      • 1970-01-01
      相关资源
      最近更新 更多