pyftpdlib运行但似乎没有监听端口,但其他ftp服务器应用程序工作

时间:2017-04-17 23:22:37

标签: python windows pyftpdlib

我正在尝试在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主机我无法telnet到运行pyftpdlib脚本的主机上的端口21。我有另一个独立的ftp服务器.exe用于Windows运行它工作正常我可以从远程Windows主机telnet到主机上的端口21我无法让pyftpdlib正常运行它,所以我知道它的没有任何FW或网络问题。

我真的很难理解为什么这个模块pyftpdlib无效。

1 个答案:

答案 0 :(得分:2)

也许是因为它正在侦听IPv6地址。试着改变这个:

address = ('0.0.0.0', 21)

到此:

my %hash;
@hash{@key} = @values;