我们遵循这个教程,并在Ubuntu 14.04上使用真棒pyftpdlib Python库创build一个FTP服务器。 这很容易设置服务器,添加用户,并创build挂钩。
有些客户端使用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()
基于这个问题 ,看起来通配符被故意排除在图书馆之外。 作为参考,这也是我自己的问题 。
任何人都可以提供更多的见解或指导我重新启用通配符?
您需要使用不同的FTP服务器。 根据文档,pyftpdlib不支持globbing。 https://github.com/giampaolo/pyftpdlib/blob/master/docs/faqs.rst#globbing-stat-command-implementation
“由于这个操作可能相当密集,无论是CPU还是内存方面,pyftpdlib都不支持通配符。”
另请参阅在pyftpdlib中恢复文件Globbing和通配符
常用的* nix命令行ftp客户端的mget命令确实依赖于NLST命令来支持globo:
$ ftp -d -v host ... ftp> mget *.php ---> TYPE A ---> PASV ---> NLST *.php mget test.php? y
如果你的FTP服务器不支持globel,那么你几乎无法做任何事情。 除非你自己编写这些function,否则什么是一个编程问题,在这里是无关紧要的。