Beispiel #1
0
def main(profiles):
    authorizer = DummyAuthorizer()
    # 将每个profile映射为一个用户
    uploadTmpRoot = tempfile.gettempdir()
    for p, c in profiles.items():
        # perm权限定义说明:
        # Read permissions:
        # "e" = change directory (CWD, CDUP commands)
        # "l" = list files (LIST, NLST, STAT, MLSD, MLST, SIZE commands)
        # "r" = retrieve file from the server (RETR command)
        # Write permissions:

        # "a" = append data to an existing file (APPE command)
        # "d" = delete file or directory (DELE, RMD commands)
        # "f" = rename file or directory (RNFR, RNTO commands)
        # "m" = create directory (MKD command)
        # "w" = store a file to the server (STOR, STOU commands)
        # "M" = change mode/permission (SITE CHMOD command) New in 0.7.0
        # 注意:投产时权限似乎应限制为只写,即:'w'
        uploadTmp = path.join(uploadTmpRoot, p)
        print uploadTmp
        if not path.isdir(uploadTmp):
            mkdir(uploadTmp)

        authorizer.add_user(p, c["upload"].get("password", ""), uploadTmp, perm="ledw")

    handler = UploadHandler
    handler.authorizer = authorizer
    handler.banner = "OSO fileserv"
    address = ("", int(getenv("FTP_PORT", "2121")))
    logging.basicConfig(filename="logs/ftp.log", level=logging.INFO)
    server = FTPServer(address, handler)
    server.max_cons = 256
    server.max_cons_per_ip = 5
    server.serve_forever()
Beispiel #2
0
 def custom_server(self, start=1):
     # TODO: finish me
     from pyftpdlib.authorizers import DummyAuthorizer
     from pyftpdlib.handlers import FTPHandler
     from pyftpdlib.servers import FTPServer
     # Generate random username and password for ftp session
     logging.debug('generating arguments')
     if not os.path.isdir(self.path):
         logging.info('%s create directory: %s' %
                      ('device.name', self.path))
         os.makedirs(self.path)
     # Add ftp user
     authorizer = DummyAuthorizer()
     logging.debug('generated args: user=%s password=%s path=%s perm=%s' %
                   (self.user, self.password, self.path, self.password))
     authorizer.add_user(self.user, self.password, self.path,
                         perm=self.perm)
     handler = FTPHandler
     handler.authorizer = authorizer
     # Instantiate FTP server class and listen
     logging.debug('%s ftp server listen on: %s %s' %
                   ('device.name', self.address, self.port))
     addr = (self.address, self.port)
     server = FTPServer(addr, handler)
     # Set a limit for connections
     server.max_cons = 32
     server.max_cons_per_ip = 5
     # Start ftp server
     logging.debug('starting disposable ftp server')
     server.serve_forever(timeout=600, blocking=False)
Beispiel #3
0
def server_start(is_verbose=False, port=None):
    if not os.path.isfile('conf.json'):
        print 'Conf file not found, please run setup.'
        sys.exit(1)
    with open('conf.json') as jd:
        template = json.load(jd)
    container.set_acc_db(str(template['user_db']), str(template['user_table']))
    container.set_shares_db(str(template['user_logs']))
    container.set_root_dir(str(template['root']))
    container.set_log_file(str(template['root']) + '/pyftpd.log')
    auth = authorizer()
    handle = handler
    handle.user_sendfile = True
    handle.timeout = None
    handle.authorizer = auth
    handle.banner = 'this is the banner'
    if port:  # untested
        address = ('', 1024)
    else:
        address = ('', 21)
    server = FTPServer(address, handle)
    server.max_cons = 256
    server.maxcons_per_ip = 1000000
    if not is_verbose:
        logging.basicConfig(filename=container.get_log_file(), level=logging.INFO)
    server.serve_forever()
Beispiel #4
0
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(konf.ftp_username,
                        konf.ftp_password,
                        '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."

    # Instantiate FTP server class and listen on 0.0.0.0:2121
    address = ('', 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()
Beispiel #5
0
def start_ftp_server():
    cs.CSClient().log(APP_NAME, 'start_ftp_server()...')
    try:
        authorizer = DummyAuthorizer()
        # Define a new user having full r/w permissions and a read-only
        # anonymous user
        authorizer.add_user('user', '12345', FTP_DIR, perm='elradfmwM')
        authorizer.add_anonymous(FTP_DIR)

        # Instantiate FTP handler class
        handler = FTPHandler
        handler.authorizer = authorizer

        # Define a customized banner (string returned when client connects)
        handler.banner = "pyftpdlib based ftpd ready."

        # Instantiate FTP server class and listen on 0.0.0.0:2121.
        # Application can only use ports higher that 1024 and the port
        # will need to be allowed in the router firewall
        address = ('', 2121)
        server = FTPServer(address, handler)

        # set a limit for connections
        server.max_cons = 256
        server.max_cons_per_ip = 5

        # start ftp server
        cs.CSClient().log(APP_NAME, 'Starting FTP server...')
        server.serve_forever()
        # This will run the server in another thread
        # t = Thread(target=server.serve_forever())
        # t.start()

    except Exception as e:
        cs.CSClient().log(APP_NAME, 'Exception occurred! exception: {}'.format(e))
    def run(self):
        """Start the FTP Server for pulsar search."""
        self._log.info('Starting Pulsar Search Interface')
        # 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(self._config['login']['user'],
                            self._config['login']['psswd'], '.',
                            perm=self._config['login']['perm'])
        authorizer.add_anonymous(os.getcwd())

        # Instantiate FTP handler class
        handler = FTPHandler
        handler.authorizer = authorizer
        handler.abstracted_fs = PulsarFileSystem

        # Define a customized banner (string returned when client connects)
        handler.banner = "SKA SDP pulsar search interface."

        # Instantiate FTP server class and listen on 0.0.0.0:7878
        address = (self._config['address']['listen'],
                   self._config['address']['port'])
        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()
Beispiel #7
0
def run(ns):
	"""starts the server."""
	auth = DummyAuthorizer()
	if ns.user is not None:
		auth.add_user(ns.user, ns.pswd, ns.path, perm=ns.perm)
	else:
		auth.add_anonymous(ns.path, perm=ns.perm)
	handler = FTPHandler
	handler.authorizer = auth
	handler.banner = "StaSh v{v} FTP-Server".format(v=_stash.__version__)
	address = ("0.0.0.0", ns.port)
	server = FTPServer(address, handler)
	server.max_cons = 128
	server.max_cons_per_ip = 128
	# setup logging
	logger = logging.getLogger("pyftpdlib")
	logger.setLevel(logging.CRITICAL)
	logger.propagate = False
	# server needs to run in a thread to be killable
	thr = threading.Thread(
		name="FTP-Server Thread", target=server.serve_forever
		)
	thr.daemon = True
	thr.start()
	print("FTP-Server started on {h}:{p}".format(h=address[0], p=str(address[1])))
	try:
		while True:
			time.sleep(0.2)
	except KeyboardInterrupt:
		print("Stopping Server...")
		server.close_all()
Beispiel #8
0
def main():
    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()
    # Define a new user having full r/w permissions
    authorizer.add_user("user_name", "pass_word", "./", perm="elradfmwM", msg_login="******", msg_quit="bye")
    # Define a read-only anonymous user
    authorizer.add_anonymous("./")

    # Instantiate FTP handler class
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.max_login_attempts = 3
    handler.permit_foreign_addresses = True
    handler.tcp_no_delay = True

    # Define a customized banner (string returned when client connects)
    handler.banner = "Welcome to my FTP."

    # Instantiate FTP server class and listen on 127.0.0.1:21
    address = ("0.0.0.0", 2121)
    server = FTPServer(address, handler)

    # set a limit for connections
    server.max_cons = 128
    server.max_cons_per_ip = 2

    absfs = AbstractedFS(u"./", handler)
    absfs.cwd = u"/bbb/ss/"
    # start ftp server
    server.serve_forever()
Beispiel #9
0
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', os.getcwd(), 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 = ('', 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()
Beispiel #10
0
def main():
    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()
    # Define a new user having full r/w permissions
    authorizer.add_user('test', 'test','./', perm='elradfmwM')
    # Define a read-only anonymous user
    authorizer.add_anonymous('./')
 
    # Instantiate TLS FTP handler class
    handler = TLS_FTPHandler
    handler.authorizer = authorizer
    handler.certfile = './server.crt'
    handler.keyfile = './server.key'
 
    # Define a customized banner (string returned when client connects)
    handler.banner = "Welcome to test's FTPS."
 
    # Instantiate FTP server class and listen on 127.0.0.1:21
    address = ('127.0.0.1', 21)
    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()
Beispiel #11
0
def main():
    ##
    #authorizer = WindowsAuthorizer()
    ## Use Guest user with empty password to handle anonymous sessions.
    ## Guest user must be enabled first, empty password set and profile
    ## directory specified.
    ##authorizer = WindowsAuthorizer(anonymous_user="******", anonymous_password="")
    #handler = FTPHandler
    #handler.authorizer = authorizer
    #ftpd = FTPServer(('', 21), handler)
    #ftpd.serve_forever()
    #return
    
    ####################
    
    # 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', os.getcwd(), perm='elradfmwM')
    #authorizer.add_anonymous(os.getcwd())
    #authorizer.add_user('addons', 'road', os.getcwd(), perm='elradfmwM')
    #authorizer.add_user('addons', 'road', xbmc.translatePath("F:\zzz__AppData\XBMC\portable_data\addons"), perm='elradfmwM')
    #authorizer.add_anonymous(xbmc.translatePath("F:\zzz__AppData\XBMC\portable_data\addons"))
    #path01=xbmc.translatePath("F:\\zzz__AppData\\XBMC\\portable_data\\addons\\")
    path01=xbmc.translatePath("F:\\zzz__AppData\\XBMC\\portable_data\\addons\\")
    path01=path01.replace("\\","|tag|").replace("|tag|","\\\\")
    #path01=path01.replace(os.sep,"|tag|").replace("|tag|","\\\\")
    #authorizer.add_anonymous(path01)
    authorizer.add_user('addons', 'xbmchub', path01, perm='elradfmwM')
    
    

    # 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 = ('', 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()
Beispiel #12
0
def server_start_testing(is_verbose=False, port=None):
    user_db = 'test_users.db'
    user_table = 'users'
    shares_db = 'test_shares.db'
    username = '******'
    password = '******'
    root = os.getcwd() + '/test_server'
    if os.path.isfile(user_db):
        os.remove(user_db)
    if os.path.isfile(shares_db):
        os.remove(shares_db)
    if os.path.isdir(root):
        rmtree(root)
    os.mkdir(root)
    ta = TableAdder(user_db, user_table)
    cols = ['name', 'status', 'password', 'salt', 'welcome', 'goodbye']
    for col in cols:
        if col == 'status':
            ta.add_column(col, 'integer')
        else:
            ta.add_column(col)
    ta.commit()
    del ta
    with TableManager(user_db, user_table) as tm:
        salt = gen_salt()
        password = gen_hash(password, salt)
        row = [username, 1, password, salt, 'welcome', 'goodbye']
        tm.quick_push(row)
    ta = TableAdder(shares_db, username)
    cols = ['time', 'ip', 'cmd', 'line', 'arg']
    for col in cols:
        ta.add_column(col)
    ta.commit()
    del ta
    container.set_acc_db(user_db, user_table)
    container.set_shares_db(shares_db)
    container.set_root_dir(root)
    container.set_log_file(root + '/pyftpd.log')
    auth = authorizer()
    handle = handler
    handle.user_sendfile = True
    handle.timeout = None
    handle.authorizer = auth
    handle.banner = 'this is the banner'
    if port:  # untested
        address = ('', port)
    else:
        address = ('', 21)
    server = FTPServer(address, handle)
    server.max_cons = 256
    server.maxcons_per_ip = 5
    if not is_verbose:
        logging.basicConfig(filename=container.get_log_file(), level=logging.INFO)
    server.serve_forever()
Beispiel #13
0
def main():
    # Parse cmdline
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("-c", "--conf", help="configuration file", default="config.json")
    parser.add_argument("-r", "--root", help="root dir", default="./")
    parser.add_argument("-p", "--port", help="listen port", type=int)
    flag = parser.parse_args()
    print flag

    # Load configuration
    cfg = json.load(open(flag.conf, "rb"))

    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()

    # Define a new user having full r/w permissions and a read-only
    perm = "elradfmwM"
    for acl in cfg.get("acls", []):
        print flag.root
        base_dir = os.path.join(flag.root, acl.get("directory", "./").lstrip("/"))
        print base_dir
        authorizer.add_user(acl["username"], acl["password"], base_dir, perm=perm)

    # anonymous user
    if cfg.get("anonymous"):
        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 = cfg.get("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 = ("", flag.port or cfg.get("port", 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()
Beispiel #14
0
def startServer():
	authorizer = DummyAuthorizer()		# create a new FTP authorizer
	
	authorizer.add_anonymous(USER_HOME + "/anonymous", perm='elradfmwM') # add anonymous user, set the directory for anonymous file uploads and give enough permissions to the anonymous user
	# permissions are denoted by the charactors 'elradfmwM'. To see what they means please visit, https://code.google.com/p/pyftpdlib/wiki/Tutorial
	
	handler = MyHandler   				# select the created custom FTP hander 
	handler.authorizer = authorizer 	# assign the authorizer to the handler
	handler.banner = "Server Ready.."	# server banner is returned when the client calls a getWelcomeMessage() call
	hostname = ""						# hostname is empty, which implies all interfaces (0.0.0.0)
	address = (hostname,21)				
	server = FTPServer(address, handler)	# start listening on port 21 on all interfaces
	
	server.max_cons = 10 				# maximum number of simultanious connections per time
	server.serve_forever()				# start the server
Beispiel #15
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('admin', 'admin123', '/srv/ftp', perm='elradfmwM')
    authorizer.add_user('student', 'student123', '/srv/ftp/student', perm='elr')
    #authorizer.add_anonymous('/tmp')

    handler = FTPHandler
    handler.authorizer = authorizer
    handler.passive_ports = range(44400, 44499)
    handler.banner = "welcome to chenfy's ftp server~"

    server = FTPServer(('0.0.0.0', 8888), handler)
    server.max_cons = 10
    server.max_cons_per_ip = 5
    server.serve_forever()
def ftp_server():
    # 实例化虚拟用户,这是FTP验证首要条件
    authorizer = DummyAuthorizer()

    # 添加用户权限和路径,括号内的参数是(用户名, 密码, 用户目录, 权限)
    # authorizer.add_user('user', '12345', '/home/', perm='elradfmw')
    user_list = get_user('conf/user.py')
    for user in user_list:
        name, passwd, permit, homedir = user
        try:
            authorizer.add_user(name, passwd, homedir, perm=permit)
        except Exception as e:
            print(e)

    # 添加匿名用户 只需要路径
    if settings.enable_anonymous == 'on':
        authorizer.add_anonymous(settings.anonymous_path)

    # 下载上传速度设置
    dtp_handler = ThrottledDTPHandler
    dtp_handler.read_limit = settings.max_download
    dtp_handler.write_limit = settings.max_upload

    # 初始化ftp句柄
    handler = FTPHandler
    handler.authorizer = authorizer

    # 日志记录
    if settings.enable_logging == 'on':
        logging.basicConfig(filename=settings.loging_name, level=logging.INFO)

    # 欢迎信息
    handler.banner = settings.welcome_msg

    # 添加被动端口范围
    handler.passive_ports = range(settings.passive_ports[0], settings.passive_ports[1])

    # 监听ip 和 端口
    server = FTPServer((settings.ip, settings.port), handler)

    # 最大连接数
    server.max_cons = settings.max_cons
    server.max_cons_per_ip = settings.max_per_ip

    # 开始服务
    print('开始服务')
    server.serve_forever()
Beispiel #17
0
def main():
    """Usually is not need, run() is called automatically when do:
      $ python -m unittest discover <SOME DIR>
    Used only for special purpose.
    """
    USAGE = \
'''Simple ftp server for testing purpose only.
Syntax: [-h] [--host=HOST] [--port=PORT] [--login=LOGIN] [--password=PASSWORD]
[--dir=DIR]
Options:
    -h                   this help
    --host=HOST          bind  to this host name or IP (localhost default)
    --port=PORT          bind to this port number (21 default)
    --login=LOGIN        user name to login (anonymous default)
    --password=PASSWORD  user password
    --dir=DIR            browse directory (current dir default)
'''
    opts = parse_cmdline()
    if opts is None:
        sys.stdout.write(USAGE)
        sys.exit(0)
    # processing other options
    host = opts.get('host', '')
    port = int(opts.get('port', 21))
    login = opts.get('login', None)
    password = opts.get('password', None)
    dir_ = opts.get('dir', os.getcwd())

    ftp_handler = FTPHandler
    authorizer = DummyAuthorizer()
    ftp_handler.authorizer = authorizer
    if login and password:
        # Define a new user having full r/w permissions
        authorizer.add_user(login, password, dir_, perm='elradfmw')
    else:
        sys.stdout.write('Run as anonymous!\n')
        authorizer.add_anonymous(dir_)

    # Define a customized banner (string returned when client connects)
    ftp_handler.banner = "Test FTP server"
    address = (host, port)
    ftpd = FTPServer(address, ftp_handler)
    # set a limit for connections
    ftpd.max_cons = 256
    ftpd.max_cons_per_ip = 256
    # start ftp server
    ftpd.serve_forever()
Beispiel #18
0
def main():
    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()

    # Creates a pass.dat file if it does not exist
    # Creates a root/admin user's folder and gives it full r/w permissions
    try:
        for line in open('pass.dat'):
            info = line.split(':')
            if len(info) < 2:
                continue
            try:
                os.mkdir(os.path.join(os.getcwd(), info[0]))
            except:
                pass
            authorizer.add_user(info[0], info[1].strip(), os.path.join(os.getcwd(), info[0]), perm='elradfmwM')
            try:
                os.mkdir(os.path.join(os.getcwd(), 'root'))
            except:
                pass
    except:
        f = open('pass.dat', 'w')
        f.close()
    authorizer.add_user('root', 'd63dc919e201d7bc4c825630d2cf25fdc93d4b2f0d46706d29038d01', os.path.join(os.getcwd()), perm='elradfmwM')

    # Instantiate FTP handler class
    handler = Handler
    handler.authorizer = authorizer

    # Define a customized banner (string returned when client connects)
    handler.banner = "OneDir Ready"

    # Instantiate FTP server class and listen on 0.0.0.0:2121
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("gmail.com",80))
    ip = str(s.getsockname()[0])
    s.close()
    address = (ip, 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()
Beispiel #19
0
def ftpstart(path01,user01="user",pass01="xbmchub",perm01='elradfmwM',port=2121,max_connections=5,max_connections_per_ip=5,anonPath=""):
    if len(path01)==0: return
    if len(anonPath)==0: anonPath=path01
    authorizer = DummyAuthorizer()
    #path01=xbmc.translatePath("F:\\zzz__AppData\\XBMC\\portable_data\\addons\\")
    #path01=path01.replace("\\","|tag|").replace("|tag|","\\\\")
    ##path01=path01.replace(os.sep,"|tag|").replace("|tag|","\\\\")
    authorizer.add_anonymous(anonPath)
    authorizer.add_user(user01, pass01, path01, perm=perm01)
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.banner = "pyftpdlib based ftpd ready."
    address = ('', port) #port=2121
    server = FTPServer(address, handler)
    server.max_cons = max_connections #256
    server.max_cons_per_ip = max_connections_per_ip #5
    notification("FTP Server","Starting Server....")
    server.serve_forever()
Beispiel #20
0
def cdn():
	logging.basicConfig(filename=os.path.join(os.getcwd(), "cdn.log.txt"), level=logging.INFO)

	with open(os.path.join(os.getcwd(), "config.json"), 'rb') as C:
		config = json.loads(C.read())

	authorizer = DummyAuthorizer()
	authorizer.add_anonymous(os.path.join(os.getcwd(), "metro_pictures"))

	handler = FTPHandler
	handler.authorizer = authorizer
	handler.banner = "DeepLab x Camille Henrot CDN"

	server = FTPServer((config['ip'], config['port']), handler)
	server.max_cons = 256
	server.max_cons_per_ip = 5

	server.serve_forever()
Beispiel #21
0
def main():
    try:
        PamAuthorizer.ALLOW_ROOT = len(os.environ['NIS'])<=1
    except:
        PamAuthorizer.ALLOW_ROOT = True
    authorizer = PamAuthorizer()

    handler = FTPHandler
    handler.authorizer = authorizer

    handler.banner = "pyftpdlib based ftpd ready."

    address = ('', 21)
    server = FTPServer(address, handler)

    server.max_cons = 256
    server.max_cons_per_ip = 5

    server.serve_forever()
Beispiel #22
0
def main():
  # auth to managing users
  authorizer = DummyMD5Authorizer()

  # add users
  hash = md5(b('12345')).hexdigest()
  authorizer.add_user('user', hash, '/home/leo/FTPRoot', perm='elradfmwM')

  handler = SimpleHandler 
  handler.authorizer = authorizer

  # loggin setting
  
  handler.banner = "Hello , my friend"
  address = ('', 2200)
  server = FTPServer(address, handler)
  server.max_cons = 256
  server.max_cons_pre_ip = 5
  server.serve_forever()
Beispiel #23
0
def main():
    authorizer = DummyAuthorizer()

    # Define a new user having full r/w permissions.
    authorizer.add_user(FTP_USER, FTP_PASSWORD, FTP_DIRECTORY, perm='elradfmw')

    handler = FTPHandler
    handler.authorizer = authorizer

    # Define a customized banner (string returned when client connects)
    handler.banner = "pyftpdlib based ftpd ready."

    # Optionally specify range of ports to use for passive connections.
    #handler.passive_ports = range(60000, 65535)

    address = ('', FTP_PORT)
    server = FTPServer(address, handler)

    server.max_cons = 256
    server.max_cons_per_ip = 5

    server.serve_forever()
Beispiel #24
0
def ftp_server():
    authorizer=DummyAuthorizer()
    user_list=get_user('conf/user.py')
    for user in user_list:
        name,passwd,permit,homedir=user
        try:
            authorizer.add_user(name,passwd,homedir,perm=permit)
        except Exception as e:
            print (e)

    #annonymous settings
    if settings.enable_anonymous=='on':
        authorizer.add_anonymous(settings.anonymous_path)

    #limit handler  
    dtp_handler=ThrottledDTPHandler
    dtp_handler.read_limit=settings.max_download
    dtp_handler.write_limit=settings.max_upload

    handler=FTPHandler
    handler.authorizer=authorizer

    if settings.enable_logging == 'on':
        logging.basicConfig(filename=settings.loging_name,level=logging.INFO)

    handler.banner=settings.welcome_msg


    #passive mod's port 
    handler.passive_ports = range(settings.passive_ports[0],settings.passive_ports[1])

    server=FTPServer((settings.ip,settings.port),handler)

    #max connect 
    server.max_cons=settings.max_cons
    server.max_cons_per_ip = settings.max_per_ip

    print('start ftp server ')
    server.serve_forever()
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

    # root="/opt/jpackagesftp/"
    # root="/mnt/wd"

    root= j.application.config.get("blobserver.paths.root")
    j.system.fs.createDir(root)

    authorizer.add_user('jpackages', 'rooter', root, 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 = "blobstor."

    # 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 = ('', 21)
    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()
Beispiel #26
0
def main():
    port = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_PORT

    authorizer = DummyAuthorizer()
    authorizer.add_user('test', 'test', '.', perm=PERMS_ALL)
    authorizer.add_anonymous(os.getcwd(), perm=PERMS_ALL)

    handler = FTPHandler
    handler.authorizer = authorizer
    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:{port}
    address = ('', port)
    server = FTPServer(address, handler)
    server.max_cons = 256
    server.max_cons_per_ip = 5

    server.serve_forever()
Beispiel #27
0
def main(host, port):
    authorizer = DummyAuthorizer()
    authorizer.add_anonymous("/opt/anonymous/", perm="lr")
   
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.banner = "ftpd ready."
    
    """ Add the port numbers here """
    handler.passive_ports = [2122]
    
    pyftpdlib.log.LEVEL = logging.DEBUG

    address = (host, port)
    server = FTPServer(address, handler)

    server.max_cons = 128
    server.max_cons_per_ip = 0

    """ Uncomment this line to disable support for PASV """
    #del handler.proto_cmds['PASV']

    server.serve_forever()
Beispiel #28
0
def setup_function(function):
    global FTPD
    
    test_dir = swpy.RESOURCE_DIR + '/test/'
 
 
    # 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(TEST_USER, TEST_PASSWD, test_dir, perm='elradfmwM')
    authorizer.add_anonymous(test_dir)

    # 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 = ('', FTP_PORT)
    FTPD = FTPServer(address, handler)

    # set a limit for connections
    FTPD.max_cons = 256
    FTPD.max_cons_per_ip = 5
    
    server_thread = threading.Thread(target=FTPD.serve_forever)       
    server_thread.start()
Beispiel #29
0
 def createServer(self,ipaddr):
     authorizer = DummyAuthorizer();
     
     ''' create a user
         All login information is stored as plaintext right now.
     '''
     authorizer.add_user("user","password", "/users/ryanwilcox/server/user", perm="elradfmwM",
     msg_login = "******", msg_quit = "bye.");
     
     authorizer.add_user("user2","passwd","/users/ryanwilcox/server/user2",perm="elradfmwM"
     msg_login = "******", msg_quit = "bye!.");
     #anon user
     authorizer.add_anonymous("/users/ryanwilcox/server");
 
     handler = FTPHandler;
     handler.authorizer = authorizer;
     handler.banner = "FileTransferProtocol";
 
     server = FTPServer((ipaddr,6066), handler);
 
     #limits on connections to ftp server
     server.max_cons = 256;
     server.max_cons_per_ip = 5;
     server.serve_forever();
Beispiel #30
0
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(
        'chellow', 'HixaNfUBOf*u', os.path.join('test', 'ftp'))

    # Instantiate FTP handler class
    handler = FTPHandler
    handler.authorizer = authorizer

    # Define a customized banner (string returned when client connects)
    handler.banner = "pyftpdlib based ftpd ready."

    server = FTPServer(('127.0.0.1', 2121), handler)

    # set a limit for connections
    server.max_cons = 256
    server.max_cons_per_ip = 5

    # start ftp server
    server.serve_forever()
Beispiel #31
0
#import Pymoult
from pymoult.highlevel.listener import Listener
from pymoult.threads import DSU_Thread

#Initialize a simple ftp server
authorizer = DummyAuthorizer()
authorizer.add_anonymous(os.path.abspath("data"))

handler = FTPHandler
handler.authorizer = authorizer
handler.banner = "Bruce"

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

server.max_cons = 256
server.max_cons_per_ip = 5

#Start Pymoult Listener
listener = Listener()
listener.start()


def main():
    server.serve_forever(timeout=0.5)


mainThread = DSU_Thread(target=main, name="mainThread")
mainThread.start()
Beispiel #32
0
def init_ftp_server():
    authorizer = DummyAuthorizer()
    """
                读权限:
                 - "e" = 改变文件目录
                 - "l" = 列出文件 (LIST, NLST, STAT, MLSD, MLST, SIZE, MDTM commands)
                 - "r" = 从服务器接收文件 (RETR command)

                写权限:
                 - "a" = 文件上传 (APPE command)
                 - "d" = 删除文件 (DELE, RMD commands)
                 - "f" = 文件重命名 (RNFR, RNTO commands)
                 - "m" = 创建文件 (MKD command)
                 - "w" = 写权限 (STOR, STOU commands)
                 - "M" = 文件传输模式 (SITE CHMOD command)
    """

    if enable_anonymous:
        # 添加匿名用户
        authorizer.add_anonymous(anonymous_path)

    # 读取配置中的用户并授权
    for user in user_list:
        name, passwd, permit, homedir = user
        try:
            authorizer.add_user(username=name,
                                password=passwd,
                                perm=permit,
                                homedir=homedir)
        except Exception as e:
            print("baseftp.ini error, please check the form of datas.")
            print(user)
            print(e)

    dtp_handler = ThrottledDTPHandler

    # 上传速度 下载速度
    dtp_handler.read_limit = max_download
    dtp_handler.write_limit = max_upload
    # Instantiate FTP handler class
    handler = FTPHandler
    handler.authorizer = authorizer

    # 是否开启记录
    if enable_logging:
        logging.basicConfig(filename="pyftp.log", level=logging.INFO)

    # 登录时显示的标题
    handler.banner = welcome_banner
    handler.masquerade_address = masquerade_address
    # 主动模式和被动模式
    handler.passive_ports = range(passive_ports[0], passive_ports[1])

    # 监听的ip和端口
    address = (ip, port)
    server = FTPServer(address, handler)

    # 设置最大连接数
    server.max_cons = max_cons
    server.max_cons_per_ip = max_pre_ip
    # 开启ftp
    server.serve_forever()
Beispiel #33
0
    {
        'name': 'test',
        'passwd': 'test',
        'homedir': '/home/test',
        'perm': 'elradfmwMT'
    },
]

authorizer = DummyAuthorizer()
for user in user_list:
    authorizer.add_user(user['name'],
                        user['passwd'],
                        user['homedir'],
                        perm=user['perm'])

dtp_handler = ThrottledDTPHandler
dtp_handler.read_limit = read_limit
dtp_handler.write_limit = write_limit

handler = FTPHandler
# handler.passive_ports = range(2000, 2300)  # 被动模式
handler.authorizer = authorizer
handler.dtp_handler = dtp_handler

logging.basicConfig(filename=log_file, level=log_level)

server = FTPServer((bind_addr, port), handler)
server.max_cons = max_connects
server.max_cons_per_ip = max_connects_pre_ip
server.serve_forever()
Beispiel #34
0
Datei: ftp.py Projekt: luotom/ftp

def main():
    users = DummyAuthorizer()
    handler = FTPHandler
    #增加被动端口
    handler.passive_ports = range(2022, 2024)
    users.add_anonymous("/home/teaching/app", perm="el")
    results = get_teacher_msgs()
    if results:
        for row in results:
            users.add_user(row[0], row[1], f"/home/teaching/app/{row[2]}", perm="elrwdmf")
            # 赋予匿名用户不同文件下不同的权限
            users.override_perm('anonymous', f"/home/teaching/app/{row[2]}/上传",
                                perm="elw", recursive=True)
            users.override_perm('anonymous', f"/home/teaching/app/{row[2]}/下载",
                                perm="elr", recursive=True)
    handler.authorizer = users
    return handler


if __name__ == '__main__':
    # 将输出写入日志中
    logging.basicConfig(filename='./log/ftpsever.log', level=logging.DEBUG)
    main_handler = main()
    server = FTPServer(sever_ip, main_handler)
    server.max_cons = max_cons
    server.max_cons_per_ip = max_cons_per_ip
    # _log_start()-> FTPServer._log_start(self)
    server.serve_forever()
def init_ftp_server():
    authorizer = DummyAuthorizer()
    """
            读权限:
             - "e" = 改变文件目录
             - "l" = 列出文件 (LIST, NLST, STAT, MLSD, MLST, SIZE, MDTM commands)
             - "r" = 从服务器接收文件 (RETR command)

            写权限:
             - "a" = 文件上传 (APPE command)
             - "d" = 删除文件 (DELE, RMD commands)
             - "f" = 文件重命名 (RNFR, RNTO commands)
             - "m" = 创建文件 (MKD command)
             - "w" = 写权限 (STOR, STOU commands)
             - "M" = 文件传输模式 (SITE CHMOD command)
    """

    if enable_anonymous:
        # 添加匿名用户
        authorizer.add_anonymous(anonymous_path)

    # 读取配置中用户并授权
    for user in user_list:
        name,passwd,permit,homedir= user
        try:
            authorizer.add_user(name, passwd, homedir, perm=permit)
        except:
            print("配置文件错误请检查是否正确匹配了相应的用户名、密码、权限、路径")
            print(user)

    dtp_handler = ThrottledDTPHandler

    # 上传速度 下载速度
    dtp_handler.read_limit = max_download
    dtp_handler.write_limit = max_upload
    # Instantiate FTP handler class
    handler = FTPHandler
    handler.authorizer = authorizer

    # 是否开启记录
    if enable_logging:
        logging.basicConfig(filename='pyftp.log', level=logging.INFO)

    # 登录时候显示的标题
    handler.banner = welcom_banner
    handler.masquerade_address = masquerade_address
    # 主动模式和被动模式
    handler.passive_ports = range(passive_ports[0], passive_ports[1])

    # 监听的ip和端口
    address = (ip, port)
    server = FTPServer(address, handler)

    # 设置最大连接数
    server.max_cons = max_cons
    server.max_cons_per_ip = max_pre_ip
    # 开启ftp
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        return
Beispiel #36
0
authorizer.add_user("user", "666666", "/", perm="elradfmw")
# 添加匿名用户,只需要路径
authorizer.add_anonymous("/")

# 初始化FTP句柄
handle = FTPHandler
handle.authorizer = authorizer

# 添加被动端口范围
handle.passive_ports = range(2000, 2333)

# 下载上传速度设置
dtp_handler = ThrottledDTPHandler
# 300kb/s
dtp_handler.read_limit = 300 * 1024
# 300kb/s
dtp_handler.write_limit = 300 * 1024
handle.dtp_handler = dtp_handler

# 监听ip和port
server = FTPServer(("0.0.0.0", 21), handle)

# 最大连接数
server.max_cons = 150
server.max_cons_per_ip = 15

# 开始服务,打印日志信息
server.serve_forever()


Beispiel #37
0
import logging
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

host = "localhost"
port = 21
username = "******"
password = "******"
folder = "./testuser"

authorizer = DummyAuthorizer()
authorizer.add_user(username, password, folder, perm="elradfmw")

handler = FTPHandler
handler.authorizer = authorizer

#logging.basicConfig(filename='./pyftpd.log', level=logging.DEBUG)

server = FTPServer((host, port), handler)
server.max_cons = 300
server.max_cons_per_ip = 10

server.serve_forever()
Beispiel #38
0
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.servers import FTPServer
from pyftpdlib.handlers import FTPHandler
import getpass
username=raw_input("Enter ftp username:"******"Enter complete path:")
authorizer = DummyAuthorizer()
authorizer.add_user(username,password,path)
handler = FTPHandler
handler.authorizer = authorizer
address = ('127.0.0.1', 21)
server = FTPServer(address, handler)
server.max_cons=512
server.max_cons_per_ip=2
server.serve_forever()
Beispiel #39
0
def start_transd(type1,ip,port,local):
	global tftpSer
	global ftpSer
	global httpSer
	global socketSer
	global conSer
	global SOC_S
	print(type1,ip,port,local)
	if type1 == "tftp":
		tftpSer = tftp.TftpServer(local)
		tftpSer.listen(ip,int(port))
	elif type1 == "ftp":
		# Instantiate a dummy authorizer for managing 'virtual' users
	    authorizer = DummyAuthorizer()
	    # Define a new user having full r/w permissions
	    authorizer.add_user('user_name', 'pass_word','./', perm='elradfmwM',msg_login='******',msg_quit='bye')
	    # Define a read-only anonymous user
	    authorizer.add_anonymous(local)
	 
	    # Instantiate FTP handler class
	    handler = FTPHandler
	    handler.authorizer = authorizer
	    handler.max_login_attempts = 3
	    handler.permit_foreign_addresses = True
	    handler.tcp_no_delay = True
	 
	    # Define a customized banner (string returned when client connects)
	    handler.banner = "Welcome to my FTP."
	 
	    # Instantiate FTP server class and listen on 127.0.0.1:21
	    address = (ip, int(port))
	    ftpSer = FTPServer(address, handler)
	 
	    # set a limit for connections
	    ftpSer.max_cons = 128 
	    ftpSer.max_cons_per_ip = 2
	 
	    absfs = AbstractedFS(unicode(local),handler)
	    #absfs.cwd = u"/bbb/ss/"
	    # start ftp server
	    ftpSer.serve_forever()
	elif type1 == "http":
		HandlerClass = SimpleHTTPRequestHandler
		ServerClass  = BaseHTTPServer.HTTPServer
		Protocol     = "HTTP/1.0"
		server_address = (ip,int(port))
		HandlerClass.protocol_version = Protocol
		httpSer = ServerClass(server_address, HandlerClass)
		sa = httpSer.socket.getsockname()
		print "Serving HTTP on", sa[0], "port", sa[1], "..."
		httpSer.serve_forever()
	elif type1 == "socket":
		#tcp
		socketSer = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		bi = socketSer.bind((ip,int(port)))
		socketSer.listen(2)
		conSer,addr = socketSer.accept()
		while SOC_S == True:
			try:
				conSer.send("hi")
				rcv = conSer.recv(10240)
				print(rcv)
				#time.sleep(3)
			except Exception, e:
				conSer.close()
				print("s1 error")
				break
		print("socket close")
		conSer.close()
Beispiel #40
0
 def ServerStart(self):
     add = (self.address, self.number)  #设置ip地址以及端口号
     ftp_server = FTPServer(add, self.ServerSet())  # 绑定ftp_handler和地址信息
     ftp_server.max_cons = self.maxconnect  # 接受的最大同时连接数 默认为512
     ftp_server.max_cons_per_ip = 0  # 接受的为同一IP地址接受的最大连接数默认为0==无限制
     return ftp_server
Beispiel #41
0
def server():
    print("Enter intrface you wanna use::")

    #Check for the available network interfaces
    intr = netifaces.interfaces()
    a = 1
    print "{:<8} {:<20}".format('$$Key', '$$Interface')
    for i in intr:
        print "{:<8} {:<20}".format(str(a), str(i))
        #print (str(a)+'.'+'  '+str(i))
        a = a + 1

    facech = raw_input("Enter :: ")
    facech = int(facech)
    facech = facech - 1
    strintr = intr[facech]

    #User chooses the interface he/she wants to work with
    intrip = netifaces.ifaddresses(strintr)[2][0]['addr']
    print('My system ip of intrfce:: ' + strintr + ' is :: ' + intrip + ' ')

    authorizer = DummyAuthorizer()

    # Define a new user having full r/w permissions and a read-only
    """
      Read permissions:
         - "e" = change directory (CWD command)
         - "l" = list files (LIST, NLST, STAT, MLSD, MLST, SIZE, MDTM commands)
         - "r" = retrieve file from the server (RETR command)
        Write permissions:
         - "a" = append data to an existing file (APPE command)
         - "d" = delete file or directory (DELE, RMD commands)
         - "f" = rename file or directory (RNFR, RNTO commands)
         - "m" = create directory (MKD command)
         - "w" = store a file to the server (STOR, STOU commands)
         - "M" = change file mode (SITE CHMOD command
    """
    read_permissions = "elr"
    write_permissions = "adfmwM"
    authorizer.add_user('akash', 'root123', '.', perm=str(write_permissions))
    authorizer.add_anonymous(os.getcwd())

    # Instantiate FTP handler class
    handler = MyHandler
    handler.authorizer = authorizer
    handler.abstracted_fs = UnixFilesystem
    handler.use_sendfile = True

    # Define a customized banner (string returned when client connects)
    handler.banner = "||cONMan is ready||."

    # Instantiate FTP server class and listen on X.X.X.X:2121
    address = (intrip, 2121)
    server = FTPServer(address, handler)

    # set a limit for connections
    server.max_cons = 256
    server.max_cons_per_ip = 5

    #enable logging
    #logging.basicConfig(filename='log/server_log.log', level=logging.DEBUG)

    # start ftp server
    server.serve_forever()
Beispiel #42
0
def run(host='0.0.0.0', port=21, mode="single"):
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)  # Log等级总开关
    fh = logging.FileHandler(filename="ftpserver.log", encoding='utf-8')
    logger.addHandler(fh)

    ftp_authorizers = DummyMD5Authorizer()
    # 添加用户权限和路径,括号内的参数是(用户名,密码,用户目录,权限)
    """
    读取权限:
    "e" =更改目录(CWD,CDUP命令)
    "l" =列表文件(LIST,NLST,STAT,MLSD,MLST,SIZE命令)
    "r" =从服务器检索文件(RETR命令)
    写入权限:
    "a" =将数据附加到现有文件(APPE命令)
    "d" =删除文件或目录(DELE,RMD命令)
    "f" =重命名文件或目录(RNFR,RNTO命令)
    "m" =创建目录(MKD命令)
    "w" =将文件存储到服务器(STOR,STOU命令)
    "M"=更改文件模式/权限(SITE CHMOD命令)0.7.0中的新增功能
    "T"=更改文件修改时间(SITE MFMT命令)1.5.3中的新增功能
    """
    hash_password = hash_md5("12345")
    home_dir = os.getcwd()
    ftp_authorizers.add_user(username='******',
                             password=hash_password,
                             homedir=home_dir,
                             perm="elradfmwMT")
    # 添加匿名用户只需要指定路径
    ftp_authorizers.add_anonymous('/tmp/')

    # 初始化ftp句柄
    ftp_handler = MyFTPHandler
    ftp_handler.authorizer = ftp_authorizers

    # Define a customized banner (string returned when client connects)
    ftp_handler.banner = "pyftpdlib based ftpd ready."

    # 添加被动端口范围
    ftp_handler.passive_ports = range(30000, 30100)

    # 下载上传速度设置, 0为无限制
    dtp_handler = ThrottledDTPHandler
    dtp_handler.read_limit = 300 * 1024  # 300kb/s
    dtp_handler.write_limit = 300 * 1024  # 300kb/s
    ftp_handler.dtp_handler = dtp_handler

    # 设置监听ip和端口,多线程模式
    if mode == "default":
        server = FTPServer((host, port), ftp_handler)
    elif mode == "threaded":
        server = ThreadedFTPServer((host, port), ftp_handler)
    elif mode == "multiprocess":
        server = MultiprocessFTPServer((host, port), ftp_handler)
    else:
        server = FTPServer((host, port), ftp_handler)

    # 设置最大连接数
    server.max_cons = 150
    server.max_cons_per_ip = 15

    # 开始服务,打印日志
    server.serve_forever()
Beispiel #43
0
# 实例化虚拟用户,这是FTP验证首要条件
authorizer = DummyAuthorizer()
# 添加用户权限和路径,括号内的参数是(用户名, 密码, 用户目录, 权限),可以为不同的用户添加不同的目录和权限
authorizer.add_user("user", "12345", data['path'], perm="elradfmw")
# 添加匿名用户 只需要路径
authorizer.add_anonymous(data['path'])

# 初始化ftp句柄
handler = FTPHandler
handler.authorizer = authorizer

#添加被动端口范围
handler.passive_ports = range(2000, 2333)

# 下载上传速度设置
dtp_handler = ThrottledDTPHandler
dtp_handler.read_limit = 3000000000 * 1024 #30000kb/s
dtp_handler.write_limit = 3000000000 * 1024 #30000kb/s


# 监听ip 和 端口,linux里需要root用户才能使用21端口
server = FTPServer((data['host'], 21), handler)

# 最大连接数
server.max_cons = 100
server.max_cons_per_ip = 100

# 开始服务,自带日志打印信息
server.serve_forever()