Example #1
0
def ftp_start():
    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()

    # Define a new user having full r/w permissions (instructor)
    authorizer.add_user('CS3103_instructor', '12345', '.', perm='elradfmwMT')
    # Define a new user having full r/w permissions except deletion (student)
    authorizer.add_user('CS3103_student', '12345', '.', perm='elrafmwMT')
    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 = (setting.ftp_server_host, setting.ftp_instructor_server_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()
Example #2
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(username=username,
                        password=password,
                        homedir=".",
                        perm="elradfmwMT")
    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 host:port
    server = FTPServer((host, port), handler)

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

    # start ftp server
    server.serve_forever()
Example #3
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()
Example #4
0
def main():
    # 新建一个用户组
    authorizer = DummyAuthorizer()
    # 将用户名,密码,指定目录,权限 添加到里面
    authorizer.add_user("root", "123456", ".", perm="elradfmwMT")  # adfmw
    # 这个是添加匿名用户,任何人都可以访问,如果去掉的话,需要输入用户名和密码,可以自己尝试
    authorizer.add_anonymous(".")

    # 带宽限制
    dtp_handler = ThrottledDTPHandler
    dtp_handler.read_limit = 1024 * 1024  # 1M/sec (1024 * 1024)
    dtp_handler.write_limit = 1024 * 1024  # 1M/sec (1024 * 1024)

    # FTP初始参数设置
    handler = MyHandler
    handler.timeout = 300
    handler.authorizer = authorizer
    handler.banner = "Ftp Ready......"  # 进入欢迎语
    handler.dtp_handler = dtp_handler

    # 日志
    logging.basicConfig(filename='Ftp.log', level=logging.INFO)

    # 开启服务器
    server = ThreadedFTPServer(("0.0.0.0", 21), handler)
    server.max_cons = 500
    server.max_cons_per_ip = 10
    server.serve_forever()
class SimpleFtpServer(multiprocessing.Process):
    def __init__(self):
        super().__init__()
        self.authorizer = DummyAuthorizer()
        handler = FTPHandler
        handler.authorizer = self.authorizer
        self.server = FTPServer(("127.0.0.1", 0), handler)

    def run(self):
        self.server.serve_forever()

    def stop(self):
        self.server.close_all()
        self.server.close()
        self.terminate()
        self.join()

    def allow_anonymous(self, cwd):
        self.authorizer.add_anonymous(cwd)

    def add_user(self, user, password, cwd):
        self.authorizer.add_user(user, password, cwd, perm="elradfmwMT")

    def base_url(self):
        return "ftp://127.0.0.1:{}".format(self.server.address[1])
Example #6
0
class FileServer:
    def __init__(self, port):
        self.port = port
        self.sharedDir = ""
        self.is_running = False
        self.ftp_handler = FTPHandler
        self.connected = 0
        self.bytesTransferred = 0
        self.filesTransferred = 0

    def setSharedDirectory(self, path):
        print "setting started"
        if not path_exists(path):
            raise FileNotFoundError
        print "hey"
        self.authorizer = DummyAuthorizer()
        self.authorizer.add_anonymous(path, perm='elradfmwM')
        self.ftp_handler.authorizer = self.authorizer

    def startServer(self):
        self.server = FTPServer(('', self.port), self.ftp_handler)
        print "process running:"
        self.server_proc = Process(target=self.server.serve_forever)
        self.server_proc.start()
        self.is_running = True

    def stopServer(self):
        if self.is_running:
            self.server.close_all()
            self.server_proc.terminate()
            self.server_proc.join()
            print("FTP server stopped")
            del self.server_proc
            self.server_proc = None
            self.is_running = False
Example #7
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()
Example #8
0
def run_anonymous_ftp(temp_dir):
    authorizer = DummyAuthorizer()
    authorizer.add_anonymous(temp_dir)
    handler = FTPHandler
    handler.authorizer = authorizer
    server = FTPServer(("127.0.0.1", PORT), handler)
    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 having full r/w permissions and a read-only
    authorizer.add_user('root', 'root', '/file-server/', perm='elradfmwMT')
    authorizer.add_anonymous('/file-server-anon/', perm='elradfmwMT')

    # Instantiate FTP handler class
    handler = FTPHandler
    handler.authorizer = authorizer
    # Passive ports
    handler.passive_ports = range(5000, 5020)
    handler.permit_foreign_addresses = True

    handler.banner = "pyftpdlib Based FTP Server"

    # connect using an address 0.0.0.0 with port 21
    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()
Example #10
0
File: ftpp.py Project: SiriusXT/FTP
    def startftp(self, username, password, port, path, perm, noname):
        logging.basicConfig(filename='resources/ftpp.log', level=logging.INFO)
        logging.info('\n\n' + time.asctime(time.localtime(time.time())))
        try:
            authorizer = DummyAuthorizer()
            authorizer.add_user(username, password, path, perm=perm)
            if noname == True:
                authorizer.add_anonymous(path)
            # Instantiate FTP handler class
            handler = FTPHandler
            handler.authorizer = authorizer
            # Define a customized banner (string returned when client connects)
            handler.banner = "pyftpdlib based ftpd ready."
            address = ('0.0.0.0', port)

            self.server = FTPServer(address, handler)
            # set a limit for connections
            self.server.max_cons = 500
            self.server.max_cons_per_ip = 50
            # start ftp server
            self.server.serve_forever(timeout=999999999)
        except Exception as e:
            self.reverse()
            self.runftp.SetLabel(u"启动失败")
            time.sleep(1)
            self.runftp.SetLabel(u"启动FTP")
            self.isrun = 0
            logging.info('\n' + str(e))
def init_ftp_server():
    authorizer = DummyAuthorizer()
    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

    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])

    address = (ip, port)
    server = FTPServer(address, handler)
    server.max_cons = max_cons
    server.max_cons_per_ip = max_pre_ip

    server.serve_forever()
Example #12
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()
def main():
    user_dir = os.path.join(FTP_ROOT, USER)
    if not os.path.isdir(user_dir):
        os.mkdir(user_dir)
    authorizer = DummyAuthorizer()
    authorizer.add_user(USER, PASSWORD, user_dir, perm="elradfmw")
    if ANONYMOUS:
        authorizer.add_anonymous("/ftp_root/nobody")

    handler = FTPHandler
    handler.authorizer = authorizer
    handler.permit_foreign_addresses = True

    passive_ports = map(int, PASSIVE_PORTS.split('-'))
    handler.passive_ports = range(passive_ports[0], passive_ports[1])

    print('*************************************************')
    print('*                                               *')
    print('*    Docker image: mikatux                      *')
    print('*    https://github.com/mikatux/ftp-server      *')
    print('*                                               *')
    print('*************************************************')
    print('SERVER SETTINGS')
    print('---------------')
    print "FTP User: "******"FTP Password: ",PASSWORD
    server = FTPServer((HOST, PORT), handler)
    server.serve_forever()
Example #14
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', 'files', perm='elradfmwMT')
    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."
    logging.basicConfig(filename='pyftpd.log', level=logging.INFO)
    handler.log_prefix = 'XXX [%(username)s]@%(remote_ip)s'
    # 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 = ('0.0.0.0', 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()
Example #15
0
def startftp(username,password,port):
    authorizer = DummyAuthorizer()
    if username!='' and password!='':
        authorizer.add_user(username,password, os.getcwd(), perm='elradfmwMT')
    else:
        authorizer.add_user('ss', 'ss', os.getcwd(), perm='elradfmwMT')
        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."

    if port == '':
        port = 21
    address = ('0.0.0.0', port)
    server = FTPServer(address, handler)

    # set a limit for connections
    server.max_cons = 200
    server.max_cons_per_ip = 50

    # start ftp server
    server.serve_forever()
Example #16
0
    def __init__(self, ftpaddr, ftpport, ftphome, rpcaddr, rpcport):
        self.ftpaddr        = ftpaddr
        self.ftpport        = ftpport
        self.ftphome        = ftphome
        
        self.rpcaddr        = rpcaddr
        self.rpcport        = rpcport
        
        logger.info("--- xagent startup ---")

        XOR.File.mkpath(self.ftphome)
        authorizer = DummyAuthorizer()
        authorizer.add_anonymous(self.ftphome, perm='elradfmwM')
        handler = FTPHandler
        handler.authorizer = authorizer
        handler.banner = "xagent ftp server ready"
        self.ftpserver = ThreadedFTPServer((self.ftpaddr, self.ftpport), handler)

        self.rpcserver = XOR.Net.XMLRPCServer(addr=(self.rpcaddr, self.rpcport), logRequests=True, allow_none=True, encoding="UTF-8")
        self.rpcserver.reg_function(XOR.OS.runex, "os.")
        self.rpcserver.reg_function(XOR.OS.type, "os.")
        self.rpcserver.reg_function(XOR.Zip.extract, "zip.")
        self.rpcserver.reg_function(XOR.File.remove, "file.")
        self.rpcserver.reg_function(self.reg_package)
        self.rpcserver.reg_function(self.shutdown)
        self.rpcserver.reg_function(self.set_logger)
        self.rpcserver.reg_function(self.del_logger)
        self.rpcserver.reg_function(self.get_ftphomedir)
        self.rpcserver.register_introspection_functions()
        self.rpcserver.register_multicall_functions()
Example #17
0
 def __init__(self, addr, homedir, *args, **kwargs):
     super(FTPServerThread, self).__init__(*args, **kwargs)
     authorizer = DummyAuthorizer()
     authorizer.add_anonymous(homedir, perm='elradfmwM')
     handler = FTPHandler
     handler.authorizer = authorizer
     self.ftpserver = ThreadedFTPServer(addr, handler)
    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()
Example #19
0
def open_ftp():
    authorizer = DummyAuthorizer()
    authorizer.add_anonymous(PUBLIC_FOLDER)
    handler = FTPHandler
    handler.authorizer = authorizer
    server = FTPServer((FTP_IP, FTP_PORT), handler)
    server.serve_forever()
Example #20
0
def main():
    port = 3334
    user = ''
    password = ''
    l = sys.argv

    if (len(l) > 1 and l[1]):
        user = l[1]

    if (len(l) > 2 and l[2]):
        password = l[2]

    if (len(l) > 3 and l[3]):
        port = int(l[3])


    authorizer = DummyAuthorizer()
    authorizer.add_user(user, password, os.getcwd(), perm='elradfmwM')
    authorizer.add_anonymous('.')

    handler = TLS_FTPHandler
    handler.certfile = CERTFILE
    handler.authorizer = authorizer

    server = FTPServer(("127.0.0.1", port), handler)
    server.serve_forever()
Example #21
0
    def run_pot(self):
        # Get config
        config = configparser.ConfigParser()
        config.read('./ftp/config.ini')
        section = 'DEFAULT'
        FTP_PORT = config[section]['ftp_port']
        FTP_USER = config[section]['ftp_user']
        FTP_PASSWORD = config[section]['ftp_password']
        FTP_DIR = config[section]['ftp_directory']
        ####################

        print("Starting FTP honeypot on port ", FTP_PORT, '...', sep='')
        authorizer = DummyAuthorizer()
        authorizer.add_user(FTP_USER, FTP_PASSWORD, FTP_DIR, perm="elradfmw")
        authorizer.add_anonymous(FTP_DIR, perm="elr")

        handler = FTPHandler
        handler.authorizer = authorizer
        #handler.log_prefix = 'XXX [%(username)s]@%(remote_ip)s'

        handler.banner = "Welcome to the FTP Server :)"

        logging.basicConfig(filename='./ftp/logs/ftp.log', level=logging.DEBUG)

        server = ThreadedFTPServer(('127.0.0.1', FTP_PORT), handler)
        server.max_cons = 10
        server.max_cons_per_ip = 5

        self.is_running = True
        print('FTP server started')
        server_thread = threading.Thread(target=server.serve_forever,
                                         daemon=True)
        server_thread.start()
Example #22
0
 def start_ftp_server(self):
     if not self.dry_run and self.args.local_ftp_server:
         self.ftp_server = None
         try:
             handler = FTPHandler
             authorizer = DummyAuthorizer()
             
             if(self.args.ftp_username and self.args.ftp_username != ""):
                 authorizer.add_user(self.args.ftp_username, self.args.ftp_password, self.ftp_output_path, perm='elradfmwMT')
             else:
                 authorizer.add_anonymous(self.ftp_output_path, perm='elradfmwMT')
             
             handler.authorizer = authorizer
             self.ftp_server = ThreadedFTPServer((self.args.local_ftp_interface, self.args.local_ftp_port), handler)
             self.ftp_server.serve_forever(blocking=False)
             
             if self.args.local_ftp_interface == "":
                 print("Started local FTP server: ::%s" % (self.args.local_ftp_port))
             else:
                 print("Started local FTP server: %s:%s" % (self.args.local_ftp_interface, self.args.local_ftp_port))
                 
         except:
             if self.args.local_ftp_interface == "":
                 print("Failed to start local FTP server on: ::%s" % (self.args.local_ftp_port))
             else:
                 print("Failed to start local FTP server on: %s:%s" % (self.args.local_ftp_interface, self.args.local_ftp_port))
             exit()
Example #23
0
def main():
    """
    Main ftp server code
    """
    with open("ABSOLUTE_PATH_OF_config.yaml", 'r') as stream:
        config = yaml.load(stream)
        authorizer = DummyAuthorizer()
        if config.get('user'):
            for each_user in config['user']:
                if not os.path.exists(each_user['details']['home_directory']):
                    os.makedirs(each_user['details']['home_directory'])
                authorizer.add_user(
                    each_user['details']['username'],
                    each_user['details']['password'],
                    each_user['details']['home_directory'],
                    perm=each_user['details']['permission']
                )
        authorizer.add_anonymous('.')
        handler = MyHandler
        handler.certfile = config['certfile']
        handler.authorizer = authorizer
        handler.masquerade_address = config['masquerade_address']
        # requires SSL for both control and data channel
        handler.tls_control_required = True
        handler.tls_data_required = True
        handler.passive_ports = range(60000, 60099)
        server = FTPServer(('', 21), handler)
        server.serve_forever()
Example #24
0
    def __init__(self, addr=None):
        os.mkdir ('server')
        os.chdir ('server')
        try:
            HOST = socket.gethostbyname ('localhost')
        except socket.error:
            HOST = 'localhost'
        USER = '******'
        PASSWD = '12345'
        HOME = getcwdu ()

        threading.Thread.__init__(self)
        self.__serving = False
        self.__stopped = False
        self.__lock = threading.Lock()
        self.__flag = threading.Event()
        if addr is None:
            addr = (HOST, 0)

        authorizer = DummyAuthorizer()
        authorizer.add_user(USER, PASSWD, HOME, perm='elradfmwM')  # full perms
        authorizer.add_anonymous(HOME)
        self.handler.authorizer = authorizer
        # lowering buffer sizes = more cycles to transfer data
        # = less false positive test failures
        self.handler.dtp_handler.ac_in_buffer_size = 32768
        self.handler.dtp_handler.ac_out_buffer_size = 32768
        self.server = self.server_class(addr, self.handler)
        self.host, self.port = self.server.socket.getsockname()[:2]
        os.chdir ('..')
Example #25
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()
Example #26
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', '.', perm='elradfmwMT')
    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 = ('127.0.0.1', 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()
Example #27
0
def main():
    port = 3334
    user = ''
    password = ''
    l = sys.argv

    if (len(l) > 1 and l[1]):
        user = l[1]

    if (len(l) > 2 and l[2]):
        password = l[2]

    if (len(l) > 3 and l[3]):
        port = int(l[3])

    authorizer = DummyAuthorizer()
    authorizer.add_user(user, password, os.getcwd(), perm='elradfmwM')
    authorizer.add_anonymous('.')

    handler = TLS_FTPHandler
    handler.certfile = CERTFILE
    handler.authorizer = authorizer

    server = FTPServer(("127.0.0.1", port), handler)
    server.serve_forever()
Example #28
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('uranus', 'abc123', '.', perm='elradfmwM')
    #authorizer.add_anonymous(os.getcwd())
    authorizer.add_anonymous("/cloudata/")

    # 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 = '47.106.75.136'
    handler.masquerade_address = '192.168.0.130'
    handler.passive_ports = range(60000, 65535)

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

    # set a limit for connections
    server.max_cons = 1000
    server.max_cons_per_ip = 10000

    # start ftp server
    server.serve_forever()
Example #29
0
def ftp():
    try:
        authorizer = DummyAuthorizer()
        if usernameentry.get() != "" or passwordentry.get() != "":
            authorizer.add_user(usernameentry.get(),
                                passwordentry.get(),
                                directoryentry.get(),
                                perm="".join(permlist))
        else:
            authorizer = DummyAuthorizer()
            authorizer.add_anonymous(directoryentry.get(),
                                     perm="".join(permlist))
        print("\n---------------------------------")
        print(
            "\nPermissions:",
            "".join(permlist),
        )
        print("\nFTP connect adress:\nftp://{}:21\n".format(localip()))
        handler = FTPHandler
        handler.authorizer = authorizer
        global server
        server = FTPServer((localip(), 21), handler)
        server.max_cons = int(maxconnectionsentry.get()) + 1
        print("Username:"******"Password:"******"Max Connections:", maxconnectionsentry.get())
        print("Ftp is running")
        server.serve_forever()
    except:
        directoryentry.delete(0, "end")
        buton["bg"] = "#3E54D3"
        buton["text"] = "Start"
        print("No such directory!")
Example #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('admin', 'admin', '/tmp/x', 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 = 2560
    server.max_cons_per_ip = 5000

    # start ftp server
    server.serve_forever()
Example #31
0
def ftpServer(dirPath, account, password):
    # 实例化用户授权管理
    authorizer = DummyAuthorizer()
    authorizer.add_user(account, password, dirPath, perm='elradfmwMT')  # 添加用户 参数:username,password,允许的路径,权限
    authorizer.add_anonymous(os.getcwd())  # 这里是允许匿名用户,如果不允许删掉此行即可

    # 实例化FTPHandler
    handler = FTPHandler
    handler.authorizer = authorizer

    # 设定一个客户端链接时的标语
    handler.banner = "pyftpdlib based ftpd ready."

    # handler.masquerade_address = '151.25.42.11'#指定伪装ip地址
    # handler.passive_ports = range(60000, 65535)#指定允许的端口范围

    address = ('0.0.0.0', 21)  # FTP一般使用21,20端口
    server = ThreadedFTPServer(address, handler)  # FTP服务器实例

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

    # 开启服务器
    server.serve_forever()
Example #32
0
def main():
    authorizer = DummyAuthorizer()
    #authorizer.add_user('user', '12345', '.', perm='elradfmwM')
    authorizer.add_user('user', '12345', '.', perm='elr')

    # cwd as home dir...should be resource dir later.
    authorizer.add_anonymous(os.getcwd())

    #dtp_handler = ThrottledDTPHandler
    #dtp_handler.read_limit = 1024000  # 1000 Kb/sec (1000 * 1024)
    #dtp_handler.write_limit = 1024000  # 1000 Kb/sec (1000 * 1024)

    #handler = FTPHandler
    #handler = TLS_FTPHandler
    handler = myHandler
    #handler.dtp_handler = dtp_handler
    handler.certfile = CERTFILE
    handler.tls_control_required = True
    handler.tls_data_required = True  # too intensive .

    handler.authorizer = authorizer
    handler.timeout = 500
    handler.max_login_attempts = 1
    handler.banner = "test"
    #handler.masquerade_address = '151.25.42.11'
    handler.passive_ports = range(60000, 60099)

    address = ("0.0.0.0", 47274)
    #address = ("192.168.1.66",47274)
    server = FTPServer(address, handler)
    server.max_cons = 20
    server.max_cons_per_ip = 3
    server.serve_forever()
Example #33
0
    def ftpserver(self):

        # 实例化虚拟用户,这是FTP验证首要条件
        authorizer = DummyAuthorizer()

        # 添加用户权限和路径,括号内的参数是(用户名, 密码, 用户目录, 权限)
        authorizer.add_user(self.var_username.get(),
                            self.var_passwd.get(),
                            self.var_path.get(),
                            perm="elradfmwMT")

        # 添加匿名用户,任何人都可以访问,否则需要输入用户名和密码才能访问
        # 匿名用户只需要配置路径
        authorizer.add_anonymous(self.var_path.get(), msg_login="******")

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

        # 监听ip和端口
        self.server = ThreadedFTPServer(
            (self.var_address.get(), self.var_port.get()), handler)

        # 开始服务
        self.server.serve_forever()
Example #34
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))
Example #35
0
def start_ftp_server():
    authorizer = DummyAuthorizer()
    authorizer.add_anonymous("ftpvista/test")
    handler = FTPHandler
    handler.authorizer = authorizer
    server = FTPServer(("127.0.0.1", 2121), handler)
    server.serve_forever()
Example #36
0
    def __init__(self, addr=None):
        os.mkdir('server')
        os.chdir('server')
        try:
            HOST = socket.gethostbyname('localhost')
        except socket.error:
            HOST = 'localhost'
        USER = '******'
        PASSWD = '12345'
        HOME = getcwdu()

        threading.Thread.__init__(self)
        self.__serving = False
        self.__stopped = False
        self.__lock = threading.Lock()
        self.__flag = threading.Event()
        if addr is None:
            addr = (HOST, 0)

        authorizer = DummyAuthorizer()
        authorizer.add_user(USER, PASSWD, HOME, perm='elradfmwM')  # full perms
        authorizer.add_anonymous(HOME)
        self.handler.authorizer = authorizer
        # lowering buffer sizes = more cycles to transfer data
        # = less false positive test failures
        self.handler.dtp_handler.ac_in_buffer_size = 32768
        self.handler.dtp_handler.ac_out_buffer_size = 32768
        self.server = self.server_class(addr, self.handler)
        self.host, self.port = self.server.socket.getsockname()[:2]
        os.chdir('..')
Example #37
0
def main():
    optargs = processCmdLineOptions()

    if not os.path.isdir(optargs.directory):
        sys.exit(
            "Directory %s not found. Please specify a different directory with -d"
            % optargs.directory)

    if optargs.verbose:
        print(optargs)

    authorizer = DummyAuthorizer()
    if not optargs.username:
        authorizer.add_anonymous(optargs.directory, perm="elradfmw")
    else:
        authorizer.add_user(optargs.username,
                            optargs.password,
                            optargs.directory,
                            perm="elradfmw")

    handler = FTPHandler
    handler.authorizer = authorizer

    server = FTPServer(("127.0.0.1", optargs.port), handler)

    server.max_cons = optargs.max_connections + 1

    server.serve_forever()
Example #38
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()
Example #39
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()
Example #40
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 #41
0
    def startServerAtFolderSettedFTP(self):
        if (self.ipAddress == None):
            raise Exception("Could not get system IP Address")
        if (self.folderToShare == None):
            raise Exception("path to folder to share is not setted")

        # 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',
                            '225588',
                            self.folderToShare,
                            perm='elradfmwMT')
        authorizer.add_anonymous(homedir=self.folderToShare)

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

        if (not (self.logToConsole)):
            config_logging(level=logging.ERROR)

        # Define a customized banner (string returned when client connects)
        handler.banner = "pyftpdlib based ftpd ready."
        address = (self.ipAddress, self.port
                   )  # listen on every IP on my machine on port 21
        server = servers.FTPServer(address, handler)
        server.serve_forever()
Example #42
0
def ftpStart(anoDir="",
             anoPerm="elr",
             ip="127.0.0.1",
             port=21,
             pasvPortBegin=60000,
             pasvPortEnd=65535,
             users=[],
             maxCons=512,
             maxConsPerIp=0):
    try:
        # step1:实例化用户授权管理
        authorizer = DummyAuthorizer()
        # step2:添加匿名用户,任何人都可以访问
        if len(anoDir) > 0:
            authorizer.add_anonymous(anoDir, perm=anoPerm)
        # step3:添加非匿名用户名,密码,指定目录,权限
        for user in users:
            authorizer.add_user(user["name"],
                                user["pwd"],
                                user["dir"],
                                perm=user["perm"])
        # step4:实例化FTPHandler
        handler = FTPHandler
        handler.authorizer = authorizer
        handler.passive_ports = range(pasvPortBegin, pasvPortEnd)
        # step5:配置服务器
        server = ThreadedFTPServer((ip, port), handler)
        server.max_cons = maxCons
        server.max_cons_per_ip = maxConsPerIp
        # step6:开启服务器
        server.serve_forever()
    except:
        print("Exception: ftp_server.ftpStart =>\n           " +
              str(sys.exc_info()))
Example #43
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user("user", "12345", ".", perm="elradfmw")
    authorizer.add_anonymous(".")
    handler = AntiFloodHandler
    handler.authorizer = authorizer
    server = FTPServer(("", 2121), handler)
    server.serve_forever(timeout=1)
Example #44
0
def main():
    authorizer = DummyAuthorizer()
#    authorizer.add_user('user', '12345', '.')
    authorizer.add_anonymous(os.getcwd(),perm='elradfmw')
    handler = FTPHandler
    handler.authorizer = authorizer
    server = ThreadedFTPServer(('0.0.0.0', 21), handler)
    server.serve_forever()
Example #45
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_anonymous("/opt/anonymous/", perm="lr")

    handler = FTPSchemeDetectionHandler
    handler.authorizer = authorizer
    server = FTPServer(('', 2121), handler)
    server.serve_forever()
Example #46
0
def run():
    authorizer = DummyAuthorizer()
    authorizer.add_user("user", "12345", r"D:\tmp", perm="elradfmw")
    authorizer.add_anonymous(r"D:\tmp")
    handler = FTPHandler
    handler.authorizer = authorizer
    server = FTPServer(("127.0.0.1", 5555), handler)
    server.serve_forever()
Example #47
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', '.', perm='elradfmw')
    authorizer.add_anonymous('.')
    handler = AntiFloodHandler
    handler.authorizer = authorizer
    server = FTPServer(('', 2121), handler)
    server.serve_forever(timeout=1)
Example #48
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('almorel', 'almorel', homedir='.', perm='elradfmw')
    authorizer.add_anonymous(homedir='.')

    handler = MyHandler
    handler.authorizer = authorizer
    server = FTPServer(('', 2121), handler)
    server.serve_forever()
Example #49
0
def ftp_main(USER, PASSWD, HOME, PORT):
	authorizer = DummyAuthorizer()
	authorizer.add_user(USER, PASSWD, HOME, perm="elradfmw")
	authorizer.add_anonymous(HOME)

	handler = FTPHandler
	handler.authorizer = authorizer

	server = FTPServer(("0.0.0.0", PORT), handler)
	server.serve_forever()
Example #50
0
def main():
	authorizer = DummyAuthorizer()
	#authorizer.add_user("user", "12345", "/home/squadhome/nwhacks16/fergenstein", perm="elradfmw")
	authorizer.add_anonymous("/home/squadhome/nwhacks16/fergenstein/objects")

	handler = FTPHandler
	handler.authorizer = authorizer

	server = FTPServer(("127.0.0.1", 21), handler)
	server.serve_forever()
Example #51
0
def main():
    """Start a stand alone anonymous FTP server."""
    usage = "python -m pyftpdlib.ftpserver [options]"
    parser = optparse.OptionParser(usage=usage, description=main.__doc__,
                                   formatter=CustomizedOptionFormatter())
    parser.add_option('-i', '--interface', default=None, metavar="ADDRESS",
                      help="specify the interface to run on (default all "
                           "interfaces)")
    parser.add_option('-p', '--port', type="int", default=2121, metavar="PORT",
                      help="specify port number to run on (default 21)")
    parser.add_option('-w', '--write', action="store_true", default=False,
                      help="grants write access for the anonymous user "
                           "(default read-only)")
    parser.add_option('-d', '--directory', default=getcwdu(), metavar="FOLDER",
                      help="specify the directory to share (default current "
                           "directory)")
    parser.add_option('-n', '--nat-address', default=None, metavar="ADDRESS",
                      help="the NAT address to use for passive connections")
    parser.add_option('-r', '--range', default=None, metavar="FROM-TO",
                      help="the range of TCP ports to use for passive "
                           "connections (e.g. -r 8000-9000)")
    parser.add_option('-v', '--version', action='store_true',
                      help="print pyftpdlib version and exit")

    options, args = parser.parse_args()
    if options.version:
        sys.exit("pyftpdlib %s" % __ver__)
    passive_ports = None
    if options.range:
        try:
            start, stop = options.range.split('-')
            start = int(start)
            stop = int(stop)
        except ValueError:
            parser.error('invalid argument passed to -r option')
        else:
            passive_ports = list(range(start, stop + 1))
    # On recent Windows versions, if address is not specified and IPv6
    # is installed the socket will listen on IPv6 by default; in this
    # case we force IPv4 instead.
    if os.name in ('nt', 'ce') and not options.interface:
        options.interface = '0.0.0.0'

    authorizer = DummyAuthorizer()
    perm = options.write and "elradfmwM" or "elr"
    authorizer.add_anonymous(options.directory, perm=perm)
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.masquerade_address = options.nat_address
    handler.passive_ports = passive_ports
    ftpd = FTPServer((options.interface, options.port), FTPHandler)
    try:
        ftpd.serve_forever()
    finally:
        ftpd.close_all()
Example #52
0
File: FTPd.py Project: jvivian/s3am
 def __init__(self, root_dir, address=None, timeout=0.001, dtp_handler=None):
     threading.Thread.__init__(self)
     self.__flag = threading.Event()
     self.__timeout = timeout
     authorizer = DummyAuthorizer()
     authorizer.add_anonymous(root_dir)
     handler = FTPHandler
     handler.authorizer = authorizer
     if dtp_handler is not None:
         handler.dtp_handler = dtp_handler
     self.server = FTPServer(address, handler)
Example #53
0
def main():
  authorizer = DummyAuthorizer()
  authorizer.add_anonymous(os.getcwd())
  for user, password, path, permission in USER_PASS_PATH_PERM:
    authorizer.add_user(user, password, path, perm=permission)

  handler = FTPHandler
  handler.authorizer = authorizer
  handler.passive_ports = range(8000, 9000)

  server = ThreadedFTPServer(('', PORT), handler)
  server.serve_forever()
Example #54
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user("user", "12345", ".", perm="elradfmw")
    authorizer.add_anonymous(".")
    handler = TLS_FTPHandler
    handler.certfile = CERTFILE
    handler.authorizer = authorizer
    # requires SSL for both control and data channel
    # handler.tls_control_required = True
    # handler.tls_data_required = True
    server = FTPServer(("", 2121), handler)
    server.serve_forever()
Example #55
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', '.', perm='elradfmw')
    authorizer.add_anonymous('.')
    handler = TLS_FTPHandler
    handler.certfile = CERTFILE
    handler.authorizer = authorizer
    # requires SSL for both control and data channel
    #handler.tls_control_required = True
    #handler.tls_data_required = True
    server = FTPServer(('', 2121), handler)
    server.serve_forever()
Example #56
0
def pyftpdlib_ftp_server():
    from pyftpdlib.authorizers import DummyAuthorizer
    from pyftpdlib.handlers import FTPHandler
    from pyftpdlib.servers import FTPServer

    auth = DummyAuthorizer()
    auth.add_anonymous('.')

    class MyFTPHandler(FTPHandler):
        authorizer = auth

    server = FTPServer((your_ip, 8081), MyFTPHandler)
    server.serve_forever()
Example #57
0
	def __init__(self, directory):
		threading.Thread.__init__(self)
		self.__serving = False
		self.__stopped = False
		self.__lock = threading.Lock()
		self.__flag = threading.Event()
		
		authorizer = DummyAuthorizer()
		authorizer.add_anonymous(directory)
		self.handler.authorizer = authorizer
		self.address = ('0.0.0.0', 2121)
		self.server = self.server_class(self.address, self.handler)
		self.host, self.port = self.server.socket.getsockname()[:2]
Example #58
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('ADING', '123456', '.', perm='elrwm')
    authorizer.add_user('ASUO', '123456', '.', perm='elrwm')
    authorizer.add_anonymous('.')
    handler = FTPHandler
    handler.authorizer = authorizer
    # requires SSL for both control and data channel
    #handler.tls_control_required = True
    #handler.tls_data_required = True
    address = ('',4000)
    logging.basicConfig(filename='./pyftpd.log',level=logging.INFO)
    server = FTPServer(address, handler)
    server.serve_forever()
Example #59
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345abcdef6789', 'c:\\', perm='elradfmw')
    authorizer.add_anonymous('.')
    handler = TLS_FTPHandler
    handler.certfile = 'cert.pem'
    gen_cer_file(handler.certfile)
    handler.authorizer = authorizer
    # requires SSL for both control and data channel
    #handler.tls_control_required = True
    #handler.tls_data_required = True
    print 'opening port on:', g_config_dict["ufs_sftp_server_port"]
    server = FTPServer(('', int(g_config_dict["ufs_sftp_server_port"])), handler)
    server.serve_forever()
Example #60
0
def setup_server(handler, server_class, addr=None):
    addr = (HOST, 0) if addr is None else addr
    authorizer = DummyAuthorizer()
    # full perms
    authorizer.add_user(USER, PASSWD, HOME, perm='elradfmwMT')
    authorizer.add_anonymous(HOME)
    handler.authorizer = authorizer
    handler.auth_failed_timeout = 0.001
    # lower buffer sizes = more "loops" while transfering data
    # = less false positives
    handler.dtp_handler.ac_in_buffer_size = 4096
    handler.dtp_handler.ac_out_buffer_size = 4096
    server = server_class(addr, handler)
    return server