我试图在windows上构建一个运行python的ftp服务器。我举了pyftpdlib的基本例子,如下所示。

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

def main():
    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()

    # Define a new user having full r/w permissions and a read-only
    # anonymous user
    authorizer.add_user('user', '12345', "c:\\temp", perm='elradfmwM')
    authorizer.add_anonymous(os.getcwd())

    # Instantiate FTP handler class
    handler = FTPHandler
    handler.authorizer = authorizer

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

    # Specify a masquerade address and the range of ports to use for
    # passive connections.  Decomment in case you're behind a NAT.
    #handler.masquerade_address = '151.25.42.11'
    #handler.passive_ports = range(60000, 65535)

    # Instantiate FTP server class and listen on 0.0.0.0:2121
    address = ('', 21)
    server = FTPServer(address, handler)

    # set a limit for connections
    server.max_cons = 256
    server.max_cons_per_ip = 5

    # start ftp server
    server.serve_forever()

if __name__ == '__main__':
    main()

当它运行/执行时,似乎在等待,没有其他东西在使用端口21。请参阅下面的流程输出。
[I 2017-04-17 19:05:55] >>> starting FTP server on :::21, pid=43124 <<<
[I 2017-04-17 19:05:55] concurrency model: async
[I 2017-04-17 19:05:55] masquerade (NAT) address: None
[I 2017-04-17 19:05:55] passive ports: None

但从远程windows主机,我无法远程登录到运行pyftpdlib脚本的主机上的端口21。我有另一个独立的ftp server.exe for windows正在运行,它运行良好我可以从远程windows主机远程登录到主机上的端口21我无法让pyftpdlib在它上正常运行,所以我知道这不是任何fw或网络问题。
我真的不明白为什么这个模块不能工作。

最佳答案

可能是因为它在监听ipv6地址。尝试更改此:

address = ('', 21)

为此:
address = ('0.0.0.0', 21)

关于python - pyftpdlib运行,但似乎没有在监听端口,但其他ftp服务器应用程序仍在工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43461155/

10-11 22:06
查看更多