• 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)
  • 相关阅读:
    HTTP 筛选器 DLL C:WindowsMicrosoft.NetFrameworkv4.0.30319aspnet_filter.dll 加载失败。数据是错误。
    win7(iis7)无法加载运行CSS文件的解决方法
    MVC异步消息推送机制
    查看目录下所有文件的行数
    解决 mac全屏时不能隐藏Dock工具栏 killall Dock
    jetty中传java参数(spring-io中的配置项)
    nginx代理前端项目
    【转】mackbook wifi卡死未响应的问题
    WeekMap WeakSet的用途
    每日新知2019-08-23
  • 原文地址:https://www.cnblogs.com/yubenliu/p/6202868.html
Copyright © 2020-2023  润新知