python ftp服务端

# -*-coding: UTF-8 -*-
import os
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

def main(username=None, password=None, ip='0.0.0.0', port=2121, path=os.getcwd()):
    authorizer = DummyAuthorizer()
    if username:
        authorizer.add_user(username, password, path, perm='elradfmwM')
    else:
        authorizer.add_anonymous(os.getcwd())

    handler = FTPHandler
    handler.authorizer = authorizer
    handler.banner = "pyftpdlib based ftpd ready."

    address = ('0.0.0.0', 2121)
    server = FTPServer(address, handler)

    server.max_cons = 256
    server.max_cons_per_ip = 5

    # start ftp server
    server.serve_forever()

if __name__ == '__main__':
    main()
posted @ 2023-08-05 23:59  静心&得意  阅读(12)  评论(0编辑  收藏  举报