• 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)
  • 相关阅读:
    scala 数据结构(七 ):集 Set
    scala 数据结构(六):映射 Map
    scala 数据结构(五):队列 Queue
    scala 数据结构(四):列表 List
    scala 数据结构(三):元组Tuple
    scala 数据结构(二):数组
    scala 数据结构(一):数据结构简介
    Scala 面向对象(十三):隐式转换和隐式参数
    vba报表制作
    Apache与Nginx
  • 原文地址:https://www.cnblogs.com/yubenliu/p/6202868.html
Copyright © 2020-2023  润新知