コード例 #1
0
ファイル: harbor_ftp.py プロジェクト: i-harbor/iharbor
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()
コード例 #2
0
ファイル: ftp2http.py プロジェクト: apnarm/ftp2http
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()
コード例 #3
0
ファイル: ftp2http.py プロジェクト: raymondbutcher/ftp2http
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()
コード例 #4
0
        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)
コード例 #5
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()