• 助手系列之python的FTP服务器


    电脑的OS是Win7,Python版本是2.7.9,安装了pip

    因为python没有内置可用的FTP SERVER,所以先选一个第三方的组件安装上,这里我选的是pyftpdlib

    pip install pyftpdlib

    安装完后可以直接用下面命令启用ftp服务器

    python –m pyftpdlib –p 21

    但这个ftp服务器没什么安全性,所以我们自己定制一个新的

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

    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', '.', 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 = ('192.168.1.205', 2121)
    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()
     
    这样我们就可以了用ftp客户端连接192.168.1.205的2121端口了
    本文出自: http://www.cnblogs.com/elautoctrl/ 如果您需要开发软硬件产品,请联系我 1986141296 elautoctrl#qq.com 欢迎您到我的淘宝小店逛逛!走过路过不要错过咧! http://shop108261664.taobao.com/
  • 相关阅读:
    解决PKIX:unable to find valid certification path to requested target 的问题
    Linux 上的常用文件传输方式介绍与比较
    用VNC远程图形化连接Linux桌面的配置方法
    红帽中出现”This system is not registered with RHN”的解决方案
    linux安装时出现your cpu does not support long mode的解决方法
    CentOS SSH配置
    es6扩展运算符及rest运算符总结
    es6解构赋值总结
    tortoisegit安装、clon、推送
    es6环境搭建
  • 原文地址:https://www.cnblogs.com/elautoctrl/p/4681314.html
Copyright © 2020-2023  润新知