python 学习笔记二 搭建ftp服务器

这是一个系列,记录我python开发常用的代码,小常识,有些是参考网上代码,(讲的可能有点烂,求不要打脸,嘤嘤嘤~~)送给那些需要的人。可以相互交流,喜欢的加我吧。
Wx: Lxp911221

这是自己搭建的ftp文件传输服务器,方便用户局域网传输,速度快。用
了 pyftpdlib.authorizers库,希望喜欢

import os  
from pyftpdlib.authorizers import DummyAuthorizer  
from pyftpdlib.handlers import FTPHandler  
from pyftpdlib.servers import FTPServer  


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('user', '12345', '/Users/zhaozikai051/Desktop/ftp', 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 = "pyftpdlib based ftpd ready."  

    # 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 = ('10.180.133.44', 2121)  
    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() 

猜你喜欢

转载自blog.csdn.net/zzk220106/article/details/81197483