1 # coding: utf-8 2 import os 3 from pyftpdlib.authorizers import DummyAuthorizer 4 from pyftpdlib.handlers import FTPHandler 5 from pyftpdlib.servers import FTPServer 6 7 def main(): 8 #实例化用户授权管理 9 authorizer = DummyAuthorizer() 10 authorizer.add_user('user','123456','/',perm='elradfmwMT') #添加用户 参数:username,password,允许的路径、权限 11 authorizer.add_anonymous(os.getcwd()) #这里是允许匿名用户 12 13 #实例化FTPHandle 14 handler = FTPHandler 15 handler.authorizer = authorizer 16 17 #设定一个客户端链接时的标语 18 handler.banner = 'pyftplib based ftpd ready.' 19 20 # handler.masquerade_address = '192.168.88.2' 21 # address = ('192.168.88.2', 21) #FTP 一般使用21、20端口 22 server = FTPServer(('127.0.0.1', 2121), handler) #FTP服务器实例 23 #设定一个限制连接 24 server.max_cons = 256 25 server.max_cons_per_ip = 5 26 27 #开启服务器 28 server.serve_forever() 29 30 if __name__ == '__main__': 31 main()