def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', '.')
    handler = FTPHandler
    handler.authorizer = authorizer
    server = MultiprocessFTPServer(('', 2121), handler)
    server.serve_forever()
Esempio n. 2
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user("user", "12345", ".")
    handler = FTPHandler
    handler.authorizer = authorizer
    server = MultiprocessFTPServer(("", 2121), handler)
    server.serve_forever()
Esempio n. 3
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', '.')
    handler = FTPHandler
    handler.authorizer = authorizer
    server = MultiprocessFTPServer(('', 2121), handler)
    server.serve_forever()
Esempio n. 4
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('admin','123456',os.getcwd(),perm='elradfmw')
 
    for user in auth.data:
        s1=user.split('=')[1]
        ret=s1.split(',')
        authorizer.add_user(ret[0].replace("'",""),ret[1],os.getcwd(),perm=ret[2].strip().replace("'",""))

    #aauthorizer.add_anonymous(os.getcwd())
    dtp_handler = ThrottledDTPHandler
    dtp_handler.read_limit=30720
    dtp_handler.write_limit=30720

    handler = FTPHandler
    handler.authorizer = authorizer
    handler.dtp_handler=dtp_handler
    logging.basicConfig(filename='%s/myftp/logs/pyftpd.log'%BASE_DIR,level=settings.level)

    handler.banner = 'pyftpdlib based ftpd ready'

    address=('',2121)
    server=MultiprocessFTPServer(address,handler)

    server.max_conns=settings.maxconn
    server.max_conns_pre_ip=settings.maxconnperip
    
    server.serve_forever()
Esempio n. 5
0
def init_server_and_run(handler):
    address = ('0.0.0.0', 21)
    server = MultiprocessFTPServer(address, handler)
    # set a limit for connections
    server.max_cons = 2048
    server.max_cons_per_ip = 2048

    # start ftp server
    server.serve_forever()
    server.close_all()
Esempio n. 6
0
def start_ftp_server(http_url, accounts, authentication_backends=(),
                     ssl_cert_path=None, http_basic_auth=False,
                     listen_host=None, listen_port=None, listen_fd=None,
                     passive_port_min=None, passive_port_max=None,
                     masquerade_address=None):

    if ssl_cert_path:

        if not os.path.exists(ssl_cert_path):
            sys.stderr.write('Cannot find SSL certificate file: %s\n' % ssl_cert_path)
            sys.exit(2)

        handler = TLS_FTPHandler
        handler.dtp_handler = TLS_PostDTPHandler

        handler.certfile = ssl_cert_path
        handler.tls_control_required = True
        handler.tls_data_required = True

    else:

        handler = FTPHandler
        handler.dtp_handler = PostDTPHandler

    if passive_port_min and passive_port_max:
        handler.passive_ports = range(passive_port_min, passive_port_max + 1)

    if masquerade_address:
        handler.masquerade_address = masquerade_address

    handler.abstracted_fs = PostFS
    handler.authorizer = AccountAuthorizer(
        accounts=accounts,
        http_basic_auth=http_basic_auth,
        backends=authentication_backends,
    )
    handler.use_sendfile = False

    PostFS.post_file = MultipartPostFile
    PostFS.post_file.url = http_url

    if listen_fd not in (None, -1):
        listen_socket = socket.fromfd(listen_fd, socket.AF_UNIX, socket.SOCK_STREAM)
        listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        listen = listen_socket
    else:
        listen = (listen_host, listen_port)

    server = MultiprocessFTPServer(listen, handler)
    server.max_cons = 256
    server.max_cons_per_ip = 5
    server.serve_forever()
Esempio n. 7
0
def start_ftp_server(http_url, accounts, authentication_backends=(),
                     ssl_cert_path=None, http_basic_auth=False,
                     listen_host=None, listen_port=None, listen_fd=None,
                     passive_port_min=None, passive_port_max=None,
                     masquerade_address=None):

    if ssl_cert_path:

        if not os.path.exists(ssl_cert_path):
            sys.stderr.write('Cannot find SSL certificate file: %s\n' % ssl_cert_path)
            sys.exit(2)

        handler = TLS_FTPHandler
        handler.dtp_handler = TLS_PostDTPHandler

        handler.certfile = ssl_cert_path
        handler.tls_control_required = True
        handler.tls_data_required = True

    else:

        handler = FTPHandler
        handler.dtp_handler = PostDTPHandler

    if passive_port_min and passive_port_max:
        handler.passive_ports = range(passive_port_min, passive_port_max + 1)

    if masquerade_address:
        handler.masquerade_address = masquerade_address

    handler.abstracted_fs = PostFS
    handler.authorizer = AccountAuthorizer(
        accounts=accounts,
        http_basic_auth=http_basic_auth,
        backends=authentication_backends,
    )
    handler.use_sendfile = False

    PostFS.post_file = MultipartPostFile
    PostFS.post_file.url = http_url

    if listen_fd not in (None, -1):
        listen_socket = socket.fromfd(listen_fd, socket.AF_UNIX, socket.SOCK_STREAM)
        listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        listen = listen_socket
    else:
        listen = (listen_host, listen_port)

    server = MultiprocessFTPServer(listen, handler)
    server.max_cons = 256
    server.max_cons_per_ip = 5
    server.serve_forever()
Esempio n. 8
0
def startftpServer(concurrytype):
    global server
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', '.')
    handler = FTPHandler
    handler.authorizer = authorizer
    if concurrytype == 'process':
        server = MultiprocessFTPServer(('', 2121), handler)
    elif concurrytype == 'thread':
        server = ThreadedFTPServer(('', 2121), handler)
    else:
        logger.info('Enter type mismatch')
    server.serve_forever()
        def tw_ftp_server():
            """ thread worker for the ftp server """
            authorizer = DummyAuthorizer()
            authorizer.add_user('user', '12345', ftp_root_dir, perm='elradfmwMT')

            # Instantiate FTP handler class
            handler = FTPHandler
            handler.authorizer = authorizer
            server = MultiprocessFTPServer(('', port), handler)
            server.max_cons = 256
            server.max_cons_per_ip = 10

            # start ftp server
            while self._com_queue.empty():
                server.serve_forever(timeout=0.1, blocking=False)
            self._com_queue.get()
            server.close_all()
            time.sleep(1)
Esempio n. 10
0
    def run_ftp(self,
                studentDirectory='./student/',
                teacherDirectory='./teacher'):
        """
        Runs a PyFTPlib FTP server to provide users with access to their task/answer documents.

        :param studentDirectory: Location of the student-accessible folder on the VM
        :type studentDirectory: string

        :param teacherDirectory: Location of the teacher-accessible folder on the VM
        :type teacherDirectory: string
        """

        authorizer = DummyAuthorizer()
        pw = '%05x' % random.randrange(16**5)
        if self.teacher:
            authorizer.add_user(username="******",
                                password=pw,
                                homedir=teacherDirectory)
        else:
            authorizer.add_user(username="******",
                                password=pw,
                                homedir=studentDirectory)
        handler = FTPHandler
        handler.authorizer = authorizer

        handler.banner = "DVNG tasks ftp server"

        # Instantiate FTP server class and listen on 0.0.0.0:2121
        address = ('', 21)
        server = MultiprocessFTPServer(address, handler)

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

        # start ftp server
        print("Task sheets are available over ftp on port 21\n" +
              "\tUsername: %s\n" % ("teacher" if self.teacher else "student") +
              "\tPassword: %s\n" % pw +
              "Keep this terminal open until you've retreived your files.")
        logging.basicConfig(level=logging.CRITICAL)
        server.serve_forever()
Esempio n. 11
0
class ftp_server:
    #Starts up FTP Server
    def __init__(self, ip='', port=2121, logs_from_pyftpdlib=False, anonymous_can_write=False):
        if not logs_from_pyftpdlib:
            ftp_log.LEVEL = ftp_log.logging.ERROR
        self._anonymous_can_write = anonymous_can_write
        self.ip = ip
        self.port = port

        #Starts up a Thread so that the main program does not hang
        Thread(target=self.main_ftp).start()
        #Waits for main_ftp to reach serve_forever
        time.sleep(1)

        return
    #Main FTP Server Thread
    def main_ftp(self):
        self.authorizer = DummyAuthorizer()

        if self._anonymous_can_write:
            self.authorizer.add_anonymous("nobody", perm="elradfmwM")
        else:
            self.authorizer.add_anonymous("nobody")

        handler = FTPHandler
        handler.authorizer = self.authorizer
        self.server = MultiprocessFTPServer((self.ip, self.port), handler)
        self.server.serve_forever(timeout=5)

    #Add user to FTP Server
    def add_user(self, user, password, root_folder, give_write_permition=True):
        if give_write_permition:
            self.authorizer.add_user(user, password, root_folder, perm="elradfmwM")
        else:
            self.authorizer.add_user(user, password, root_folder)
        print('[FTP SERVER] User Added: '+user)

    def clean_up(self):
        self.server.close_all()
Esempio n. 12
0
    def run_job(self):
        soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
        resource.setrlimit(resource.RLIMIT_NOFILE, (hard, hard))

        password = secrets.token_hex(32)

        # TODO: find a better way to enable automatic cluster creation
        # TODO: or require password authentication for accessing redis/webdis
        self.redis_client.set("tmp_dockex_ftpd_password", password)

        authorizer = DummyAuthorizer()
        authorizer.add_user("dockex",
                            password,
                            self.params["path"],
                            perm="elradfmwMT")
        handler = FTPHandler
        handler.authorizer = authorizer
        server = MultiprocessFTPServer((self.ip_address, self.port), handler)

        server.max_cons = 0

        server.serve_forever()
Esempio n. 13
0
def main():
    # configuracao de log
    logger = logging.getLogger()
    ch = logging.StreamHandler(sys.stdout)
    logger.setLevel(logging.DEBUG)
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    # fim configuracao de log

    # usando os usuarios UNIX
    authorizer = UnixAuthorizer(rejected_users=["root"],
                                require_valid_shell=True)
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.abstracted_fs = UnixFilesystem
    handler.log_prefix = "%(username)s@%(remote_ip)s"
    #logger.basicConfig(filename='/var/log/pyftpd.log', level=logging.INFO)
    # utilizando o servidor multiprocesso
    server = MultiprocessFTPServer(('', 21), handler)
    server.serve_forever()
Esempio n. 14
0
if os.name == 'posix':
    authorizer = UnixAuthorizer()
# Trying to get Windows to work...
#elif os.name == 'nt':
#    authorizer = WindowsAuthorizer()
else:
    try:
        OperatingSystemError(
            print(
                "[WARN]: Your operating system isn't supported! This software runs only on Unix machines!"
            ))
    except OperatingSystemError:
        print("[WARN]: This shouldn't happen but alrighty then!")
        exitError(str(-1))
        sys.exit(0)

handler = FTPHandler
handler.authorizer = authorizer

while isRunning:

    #setproctitle.setproctitle("lftpd")
    FTPLogInfo(("Starting Lame FTP service on ", bindport))
    print("Press Ctrl-C to stop the servicing!")
    server = MultiprocessFTPServer((bindip, bindport), handler)
    server.serve_forever()

    if (Interrupt()):
        isRunning == False
        sys.exit(0)