Example #1
0
def main(res):
    creds = res[0]
    runargs = res[1]
    if runargs.port == 21:
        if os.getuid() != 0:
            parser.print_help(sys.stderr)
            raise OSError("Bind Port 21 Need Root privileges.")
    if runargs.cwd:
        servroot = str(pathlib.Path(runargs.cwd).resolve())
    authorization = DummyAuthorizer()
    if runargs.username and runargs.password:
        authorization.add_user(runargs.username,
                               runargs.password,
                               homedir=servroot,
                               perm="elradfmwMT")
    if runargs.anonymous:
        authorization.add_anonymous(homedir=servroot, perm="elrmwM")
    if len(creds) > 0:
        for i in creds:
            authorization.add_user(i[0],
                                   i[1],
                                   homedir=servroot,
                                   perm="elradfmwMT")
    hand = FTPHandler
    hand.authorizer = authorization
    hand.banner = "Welcome To My FTP"
    address = ('', runargs.port)
    server = FTPServer(address, hand)
    server.max_cons = 15
    server.max_cons_per_ip = 5
    server.set_reuse_addr()
    server.serve_forever()
Example #2
0
def make_ftp_server():

    class DummyFtpServer:
        """Just a mock to make the FTP code happy when
        there is no server available"""

        def serve_forever(self, *args, **kwargs):
            pass

        def close_all(self, *args, **kwargs):
            pass

    try:
        ftp_handler = FTPHandler
        ftp_handler.authorizer = MyAuthorizer()
        ftp_handler.abstracted_fs = MyFilesystem

        ftp_handler.banner = "fus at your service."
        address = (config.get("global", "host"),
                   config.getint("global", "ftp_port"))
        ftp_server = FTPServer(address, ftp_handler)
        ftp_server.set_reuse_addr()

        return ftp_server
    except NoOptionError:
        logging.warning("Not running FTP server, is 'ftp_port' configured?")
    except Exception:
        logging.warning("Not running FTP server, is pyftpdlib available?")

    return DummyFtpServer()