python ---- ftp传输服务器[在本地建一个站点方便局域网访问]
分享一个python 脚本 关于建立ftp服务器以供局域网内的同事访问
ftp.py
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 8 def main(): 9 # Instantiate a dummy authorizer for managing 'virtual' users 10 authorizer = DummyAuthorizer() 11 12 # Define a new user having full r/w permissions and a read-only 13 # anonymous user 14 authorizer.add_user('user', '12345', 'Z:\wwwroot\c++', perm='elradfmwM') 15 # authorizer.add_anonymous(os.getcwd()) 16 17 # Instantiate FTP handler class 18 handler = FTPHandler 19 handler.authorizer = authorizer 20 21 # Define a customized banner (string returned when client connects) 22 handler.banner = "pyftpdlib based ftpd ready." 23 24 # Specify a masquerade address and the range of ports to use for 25 # passive connections. Decomment in case you're behind a NAT. 26 #handler.masquerade_address = '151.25.42.11' 27 #handler.passive_ports = range(60000, 65535) 28 29 # Instantiate FTP server class and listen on 0.0.0.0:2121 30 address = ('0.0.0.0', 2121) 31 server = FTPServer(address, handler) 32 33 # set a limit for connections 34 server.max_cons = 256 35 server.max_cons_per_ip = 5 36 37 # start ftp server 38 server.serve_forever() 39 40 if __name__ == '__main__': 41 main()
先安装 pyftpdlib 之后根据自己的用户名和密码和对应的传输路径,修改这一行
authorizer.add_user('user', '12345', 'Z:\wwwroot\c++', perm='elradfmwM')
运行
python ftp.py