1. 程式人生 > >python ---- ftp傳輸伺服器[在本地建一個站點方便區域網訪問]

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