使用ftputil无法列出目录

时间:2014-03-11 18:03:07

标签: python python-3.x

所以,

我正在尝试列出ftp服务器上当前目录的内容,然后在文件上传后列出目录,但它不像我预期的那样工作:

#!/usr/bin/env python
# -*- coding: utf-8 -*-


import ftplib
import ftputil


class OpenFTPSession(ftplib.FTP):

    def __init__(self, address, user, password, port):
        """
        port variable must be passed as int to avoid:
        File "C:\Python33\lib\ftplib.py", line 144, in connect
            if port > 0:
        TypeError: unorderable types: str() > int()
        """
        ftplib.FTP.__init__(self)
        self.connect(address, int(port))
        self.login(user, password)


class FileTransferUtils(object):

    def __init__(self, address, user, password, remote_path, port):
        self.host = address.split(':')[0]
        self.start = ftputil.FTPHost(self.host, user, password, remote_path, port=port, session_factory=OpenFTPSession)
        self.start.chdir(remote_path)

    def upload(self, filename):
        try:
            self.start.upload(filename, filename)
            self.start.listdir('/healthy_food/bacon_recipes')

            return True
        except Exception:
            raise


ftp_connect = resource_utilities.FileTransferUtils(
    self.address, self.user, self.password, self.remote_path, self.ftp_port
)

for package in glob.glob("*.zip"):
    #print("   Package: {}".format(package))
    #os.chmod(package, 0o666)
    # Upload package
    ftp_connect.upload(package)

错误讯息:

  File "C:\Python33\lib\site-packages\ftputil\stat.py", line 499, in _real_listdir
    format(path))
ftputil.error.PermanentError: 550 /healthy_food/bacon_recipes: no such directory or wrong directory parser used
Debugging info: ftputil 3.0, Python 3.3.4 (win32)

提前致谢。

0 个答案:

没有答案