zoukankan      html  css  js  c++  java
  • Linux下pyftplib简单的脚本

    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('admin', '12345', '/root',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 = "Simple FTPServer."
    
    # 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.3.177', 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()

    关于脚本的一些说明:
    建立一个authorizer = DummyAuthorizer() 对象的实例
    利用.add_user方法添加一个用户 authorizer.add_user('admin', '12345', '/root',perm='elradfmwM')
    关于建立用户的参数的说明:
    admin 用户名
    '12345' 密码
    /root 用户的根目录
    perm='elradfmwM' 设置用户的权限

    关于perm='elradfmwM' 参数介绍:
    Read permissions:
    - "e" = change directory (CWD command)
    - "l" = list files (LIST, NLST, STAT, MLSD, MLST, SIZE, MDTM commands)
    - "r" = retrieve file from the server (RETR command)

    Write permissions:
     - "a" = append data to an existing file (APPE command)
     - "d" = delete file or directory (DELE, RMD commands)
     - "f" = rename file or directory (RNFR, RNTO commands)
     - "m" = create directory (MKD command)
     - "w" = store a file to the server (STOR, STOU commands)
     - "M" = change file mode (SITE CHMOD command)
  • 相关阅读:
    EF 连接数据库 Mysql (database first ) 一个表对应一个模型
    EF Database first 中,实现 多个表对应一个 实体的 查询
    用五分钟重温委托,匿名方法,Lambda,泛型委托,表达式树 (转sam xiao的博客)
    转,竞争中的操作手法
    最近想买的东西
    换书网,互相换书看
    在线模拟城市
     下面我列出了一些和VC商谈时必须解决的问题。
    时代杂志:生活中离不开的25个网站
    运营社区需要心理学
  • 原文地址:https://www.cnblogs.com/yubenliu/p/6202868.html
Copyright © 2011-2022 走看看