<commit_before>"""A basic FTP server which uses a DummyAuthorizer for managing 'virtual
users', setting a limit for incoming connections.
"""

import os
import yaml

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

this_dir = os.path.dirname(os.path.abspath(__file__))
print(this_dir)

def get_server(config_file=os.path.join(this_dir, '../conf/ftp.conf')):
    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()

    conf_file = file(config_file, 'r')

    conf = yaml.safe_load(conf_file)
    print(conf)
    # Create users
    for user in conf.get('users'):
        authorizer.add_user(user.get('name'), user.get('password'), user.get('dir'), perm=user.get('permission'))

    # TODO: implement anon user
    # 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 = "simpleftp ready!"

    # Instantiate FTP server class and listen on 0.0.0.0:2121
    server = conf.get('server', {})

    handler.masquerade_address = server.get('masquerade_address', None)
    range_start = min(server.get('passive_ports', {}).get('start', 60000), 65535)
    range_end = server.get('passive_ports', {}).get('end', max((range_start + 5000), 65535))
    # import pdb; pdb.set_trace()
    handler.passive_ports = range(range_start, range_end)
    address = (server.get('address', ''), server.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()
    return server

if __name__ == '__main__':
    server = get_server()
    server.serve_forever()<commit_msg>Added sendfile option<commit_after>"""A basic FTP server which uses a DummyAuthorizer for managing 'virtual
users', setting a limit for incoming connections.
"""

import os
import yaml

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

this_dir = os.path.dirname(os.path.abspath(__file__))
print(this_dir)

def get_server(conf=None, config_file=os.path.join(this_dir, '../conf/ftp.conf')):

    conf_file = file(config_file, 'r')
    conf = yaml.safe_load(conf_file)
    print(conf)
    # Create users
    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()
    for user in conf.get('users'):
        authorizer.add_user(user.get('name'), user.get('password'), user.get('dir'), perm=user.get('permission'))

    # TODO: implement anon user
    # 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 = "simpleftp ready!"

    # Instantiate FTP server class and listen on 0.0.0.0:2121
    server = conf.get('server', {})

    handler.masquerade_address = server.get('masquerade_address', None)
    range_start = min(server.get('passive_ports', {}).get('start', 60000), 65535)
    range_end = server.get('passive_ports', {}).get('end', max((range_start + 5000), 65535))
    # import pdb; pdb.set_trace()
    handler.passive_ports = range(range_start, range_end)

    handler.use_sendfile = server.get('use_sendfile', 'False')

    address = (server.get('address', ''), server.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()
    return server

if __name__ == '__main__':
    server = get_server()
    server.serve_forever()
{'fraction_non_alphanumeric': 0.12348855158219707, 'fraction_numerical': 0.018008747105737074, 'mean_word_length': 4.109067017082785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '284811', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1226, 'n_words': 303}