在pyftpdlib中恢复通配符支持

时间:2017-11-10 00:41:20

标签: python ftp wildcard pyftpdlib

从giampaolo / pyftpdlib库中删除了通配符支持。在r358之前可以使用全局功能。我们可以回到r357查看删除的内容并重新实现它。 https://github.com/giampaolo/pyftpdlib/issues/106#issuecomment-44425620

不支持对通配符进行全局处理(例如,NLST *.txt不起作用)。 “ - 来自合规文档https://github.com/giampaolo/pyftpdlib/blob/64d629aa480be4340cbab4ced1213211b4eee8db/docs/rfc-compliance.rst

此外,他建议使用MLSD而不是NLST作为可能的解决方案。 https://github.com/giampaolo/pyftpdlib/issues/106#issuecomment-44425620。我的猜测是,通过对库的修改,可以恢复通配符功能。

有没有人知道如何实现这个目标?

其他细节:

我们跟随this tutorial并使用令人敬畏的pyftpdlib Python库在Ubuntu 14.04上创建了一个FTP服务器。设置服务器,添加用户和创建挂钩很容易。

有些客户使用mget直接从他们的服务器与我们的FTP服务器通信。如果直接指定文件名,则mget命令有效,但传递通配符失败。以下是一个示例回复:

ftp> dir
229 Entering extended passive mode (|||26607|).
125 Data connection already open. Transfer starting.
-rw-r--r--   1 serverpilot serverpilot      914 Oct 06 19:05 index.php
226 Transfer complete.
ftp> mget *.php
No such file or directory.
ftp> glob
Globbing off.
ftp> mget *.php
mget *.php [anpqy?]? y
229 Entering extended passive mode (|||60975|).
550 No such file or directory.
ftp> mget index.php
mget index.php [anpqy?]? y
229 Entering extended passive mode (|||17945|).
125 Data connection already open. Transfer starting.
100% |***************************************************************************************************************************************************************|   914      763.53 KiB/s    00:00 ETA
226 Transfer complete.
914 bytes received in 00:00 (692.99 KiB/s)

我们的脚本如下所示:

from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer


# The port the FTP server will listen on.
# This must be greater than 1023 unless you run this script as root.
FTP_PORT = 2121

# The name of the FTP user that can log in.
FTP_USER = "myuser"

# The FTP user's password.
FTP_PASSWORD = "change_this_password"

# The directory the FTP user will have full read/write access to.
FTP_DIRECTORY = "/srv/users/serverpilot/apps/APPNAME/public/"


def main():
    authorizer = DummyAuthorizer()

    # Define a new user having full r/w permissions.
    authorizer.add_user(FTP_USER, FTP_PASSWORD, FTP_DIRECTORY, perm='elradfmw')

    handler = FTPHandler
    handler.authorizer = authorizer

    # Define a customized banner (string returned when client connects)
    handler.banner = "pyftpdlib based ftpd ready."

    # Optionally specify range of ports to use for passive connections.
    #handler.passive_ports = range(60000, 65535)

    address = ('', FTP_PORT)
    server = FTPServer(address, handler)

    server.max_cons = 256
    server.max_cons_per_ip = 5

    server.serve_forever()


if __name__ == '__main__':
    main()

根据this issue,有意将通配符遗漏在库中。作为参考,这里也是my own issue

任何人都可以提供更多见解或指导我重新启用通配符吗?

0 个答案:

没有答案