Example #1
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 #2
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()
    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 #4
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 #5
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(konf.ftp_username,
                        konf.ftp_password,
                        'ftp/',
                        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."

    # 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()
def ftp_server(command_line_object):
    # current directory
    exfil_directory = os.path.join(os.getcwd(), "data")
    loot_path = exfil_directory + "/"

    # Check to make sure the agent directory exists, and a loot
    # directory for the agent.  If not, make them
    if not os.path.isdir(loot_path):
        os.makedirs(loot_path)

    try:
        authorizer = DummyAuthorizer()
        authorizer.add_user(
            command_line_object.username, command_line_object.password,
            loot_path, perm="lrw")

        handler = FTPHandler
        handler.authorizer = authorizer

        # Define a customized banner (string returned when client connects)
        handler.banner = "Connecting to Egress-Assess's FTP server!"

        server = FTPServer(('', 21), handler)
        server.serve_forever()
    except ValueError:
        print "[*] Error: The directory you provided may not exist!"
        print "[*] Error: Please re-run with a valid FTP directory."
        sys.exit()
Example #7
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("/home/nobody")

    handler = FTPHandler
    handler.authorizer = authorizer

    logging.basicConfig(level=logging.DEBUG)

    server = FTPServer(("127.0.0.1", port), handler)
    server.serve_forever()
Example #8
0
    def serve(self):
        # current directory
        exfil_directory = os.path.join(os.getcwd(), "data")
        loot_path = exfil_directory + "/"

        # Check to make sure the agent directory exists, and a loot
        # directory for the agent.  If not, make them
        if not os.path.isdir(loot_path):
            os.makedirs(loot_path)

        try:
            authorizer = DummyAuthorizer()
            authorizer.add_user(
                self.username, self.password,
                loot_path, perm="elradfmwM")

            handler = FTPHandler
            handler.authorizer = authorizer

            # Define a customized banner (string returned when client connects)
            handler.banner = "Connecting to Egress-Assess's FTP server!"

            try:
                server = FTPServer(('', self.port), handler)
                server.serve_forever()
            except socket.error:
                print "[*][*] Error: Port %d is currently in use!" % self.port
                print "[*][*] Error: Please restart when port is free!\n"
                sys.exit()
        except ValueError:
            print "[*] Error: The directory you provided may not exist!"
            print "[*] Error: Please re-run with a valid FTP directory."
            sys.exit()
        return
Example #9
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 #10
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user("user", "12345", ".")
    handler = FTPHandler
    handler.authorizer = authorizer
    server = ThreadedFTPServer(("", 2121), handler)
    server.serve_forever()
Example #11
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 #12
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 #13
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', '.')
    handler = FTPHandler
    handler.authorizer = authorizer
    server = MultiprocessFTPServer(('', 2121), handler)
    server.serve_forever()
Example #14
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)
Example #15
0
class Server(threading.Thread):
	def __init__(self, ip, path, users, port, password):
		super(Server, self).__init__()
		self.ip = ip
		self.path = path
		self.users = users
		self.port = port
		self.auth = DummyAuthorizer()
		self.handler = CustomFTP(self.auth, self.port, path, password)
		# self.handler.authorizer = self.auth
		print 'starting server on port %d' % (self.port)
		[self.add_user(self.path, u, password) for u in self.users]

	def start_thread(self):
		self.start()
		return self

	def add_user(self, path, user, password):
		pathn = os.path.join(path, str(self.port))
		if not os.path.exists(pathn): os.mkdir(pathn)
		self.auth.add_user(user, password, pathn, perm="elr") # elradfmw

	def run(self):
		self.server = ThreadedFTPServer((self.ip, self.port), self.handler)
		self.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 run_server(cls):
     authorizer = DummyAuthorizer()
     authorizer.add_user("user", "password", cls.ftp_dir, perm="elrd")
     handler = FTPHandler
     handler.authorizer = authorizer
     cls.ftpd = FTPServer(("0.0.0.0", 8021), handler)
     cls.ftpd.serve_forever(timeout=0.2, handle_exit=True)
Example #18
0
def main(profiles):
    authorizer = DummyAuthorizer()
    # 将每个profile映射为一个用户
    uploadTmpRoot = tempfile.gettempdir()
    for p, c in profiles.items():
        # perm权限定义说明:
        # Read permissions:
        # "e" = change directory (CWD, CDUP commands)
        # "l" = list files (LIST, NLST, STAT, MLSD, MLST, SIZE commands)
        # "r" = retrieve file from the server (RETR command)
        # Write permissions:

        # "a" = append data to an existing file (APPE command)
        # "d" = delete file or directory (DELE, RMD commands)
        # "f" = rename file or directory (RNFR, RNTO commands)
        # "m" = create directory (MKD command)
        # "w" = store a file to the server (STOR, STOU commands)
        # "M" = change mode/permission (SITE CHMOD command) New in 0.7.0
        # 注意:投产时权限似乎应限制为只写,即:'w'
        uploadTmp = path.join(uploadTmpRoot, p)
        print uploadTmp
        if not path.isdir(uploadTmp):
            mkdir(uploadTmp)

        authorizer.add_user(p, c["upload"].get("password", ""), uploadTmp, perm="ledw")

    handler = UploadHandler
    handler.authorizer = authorizer
    handler.banner = "OSO fileserv"
    address = ("", int(getenv("FTP_PORT", "2121")))
    logging.basicConfig(filename="logs/ftp.log", level=logging.INFO)
    server = FTPServer(address, handler)
    server.max_cons = 256
    server.max_cons_per_ip = 5
    server.serve_forever()
Example #19
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()
Example #20
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 #21
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 #22
0
 def custom_server(self, start=1):
     # TODO: finish me
     from pyftpdlib.authorizers import DummyAuthorizer
     from pyftpdlib.handlers import FTPHandler
     from pyftpdlib.servers import FTPServer
     # Generate random username and password for ftp session
     logging.debug('generating arguments')
     if not os.path.isdir(self.path):
         logging.info('%s create directory: %s' %
                      ('device.name', self.path))
         os.makedirs(self.path)
     # Add ftp user
     authorizer = DummyAuthorizer()
     logging.debug('generated args: user=%s password=%s path=%s perm=%s' %
                   (self.user, self.password, self.path, self.password))
     authorizer.add_user(self.user, self.password, self.path,
                         perm=self.perm)
     handler = FTPHandler
     handler.authorizer = authorizer
     # Instantiate FTP server class and listen
     logging.debug('%s ftp server listen on: %s %s' %
                   ('device.name', self.address, self.port))
     addr = (self.address, self.port)
     server = FTPServer(addr, handler)
     # Set a limit for connections
     server.max_cons = 32
     server.max_cons_per_ip = 5
     # Start ftp server
     logging.debug('starting disposable ftp server')
     server.serve_forever(timeout=600, blocking=False)
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
class MyServerFtp:
	
	def __init__(self):
		self.error = False
		self.port = 2121
	def __exit__(self, *err	):
        	self.close()
	def serverStart(self,port,location):
		try:
			self.error = False
			self.authorizer = DummyAuthorizer()
			self.authorizer.add_user('user', 'sk', location , perm='elradfmwM')

			self.handler = FTPHandler
			self.handler.authorizer = self.authorizer

			self.handler.banner = "ftp Server ready"
			self.address = ('', port)
			self.server = FTPServer(self.address, self.handler)
	
			self.server.max_cons = 256
			self.server.max_cons_per_ip = 5
			
			self.thread = threading.Thread(target = self.server.serve_forever)
			self.thread.deamon = True
			self.thread.start()
		except socket.error:
			self.error = True
			pass

	def errorOccured(self):
		return self.error

	def serverStop(self):
		self.server.close_all()
Example #25
0
File: ftpd.py Project: Schnobb/ftpd
def main(args):
    user = DEFAULT_USER
    password = DEFAULT_PASSWORD
    ip = DEFAULT_IP
    port = DEFAULT_PORT
    directory = args.directory
    permissions = DEFAULT_PERM
    
    if args.user:
        user = args.user
    
    if args.password:
        password = args.password
        
    if args.ip:
        ip = args.ip
        
    if args.port:
        port = args.port
        
    authorizer = DummyAuthorizer()
    authorizer.add_user(user, password, directory, perm=permissions)
    
    #handler = TLS_FTPHandler
    #handler.certfile = 'server.crt'
    handler = FTPHandler
    handler.authorizer = authorizer
    
    server = FTPServer((ip, port), handler)
    server.serve_forever()
Example #26
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 #27
0
 def handle(self, *args, **options):
     authorizer = DummyAuthorizer()
     authorizer.add_user('user', '12345', '.', perm='elradfmw')
     ftp_handler = FTPHandler
     ftp_handler.authorizer = authorizer
     ftp_handler.abstracted_fs = YourFS
     ftpd = FTPServer(('', 21), ftp_handler)
     ftpd.serve_forever()
Example #28
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 #29
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 #30
0
def run_server():
    tempdir = tempfile.mkdtemp()
    authorizer = DummyAuthorizer()
    authorizer.add_user(FTP_USERNAME, FTP_PASSWORD, tempdir, perm="elradfmw")
    handler = S3FtpUploadHandler
    handler.authorizer = authorizer
    server = FTPServer((BIND_ADDRESS, PORT), handler)
    server.serve_forever()
Example #31
0
def ftp_server():
    authorizer = DummyAuthorizer()
    user_list = get_user('conf/user.conf')
    for user in user_list:
        name, password, permit, homedir = user
        try:
            authorizer.add_user(name, password, homedir, perm=permit)
        except Exception as e:
            print(e)

    if setting.enable_anonymous == 'on':
        authorizer.add_anonymous('/home/')

    dtp_handler = ThrottledDTPHandler
    dtp_handler.read_limit = setting.max_download
    dtp_handler.write_limit = setting.max_upload

    handler = FTPHandler
    handler.authorizer = authorizer

    if setting.enable_logging == 'on':
        logger.config_logger()

    handler.banner = setting.welcome_msg

    handler.passive_ports = range(setting.passive_ports[0],
                                  setting.passive_ports[1])

    server = FTPServer((SERVER_IP, SERVER_PORT), handler)
    server.max_cons = setting.max_cons
    server.max_cons_per_ip = setting.max_per_ip

    server.serve_forever()
Example #32
0
def start_FTP_server():
    global authorizer, handler, server

    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()

    # Define two users with full r/w permissions, one for each camera
    user_home_folder = os.getenv("HOME")
    authorizer.add_user('camright', 'miaa', user_home_folder, perm='elradfmwM')
    authorizer.add_user('camleft', 'miaa', user_home_folder, perm='elradfmwM')
    print(user_home_folder)

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

    # Define a customized banner (string returned when client connects)
    handler.banner = "pyftpdlib based ftpd ready."
    handler.permit_privileged_ports = True

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

    # set a limit for connections
    server.max_cons = 512
    server.max_cons_per_ip = 0  # 0 == no limit

    # start ftp server
    server.serve_forever()
    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 #34
0
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 #35
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()
    def startserver(self):
        # 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.user, self.password, './sharefolder',msg_login="******", msg_quit="Goodbye.", perm='elradfmwM')
        authorizer.add_anonymous(os.getcwd())

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

        # Define a customized banner (string returned when client connects)
        handler.banner = "A client is connected with your server."

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

        server = FTPServer(address, handler)

        # set a limit for connections
        server.max_cons = allowed_connection
        server.max_cons_per_ip = allowed_connection_per_ip

        # start ftp server
        server.serve_forever()
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.server_proc.join()
        '''try:
            Thread(target=self.server.serve_forever, args=()).start()
        except Exception, errtxt:
            print errtxt'''
        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
def ftpServer():
    # 实例化用户授权管理
    authorizer = DummyAuthorizer()
    authorizer.add_user(
        'getUploadFile',
        'getUploadFile',
        "%s/uploads" % LogConfig.dirfilePath,
        perm='elradfmwMT')  # 添加用户 参数:username,password,允许的路径,权限
    authorizer.add_user(
        'setAPITaskReports',
        'setAPITaskReports',
        "%s/reports" % LogConfig.dirfilePath,
        perm='elradfmwMT')  # 添加用户 参数:username,password,允许的路径,权限
    # authorizer.add_anonymous("%s/AutotestWebD/reports" % rootDir, perm='elradfmwMT')  # 这里是允许匿名用户,如果不允许删掉此行即可

    # 实例化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 = (TcpServerConf.ip, TcpServerConf.ftpport)  # FTP一般使用21,20端口
    server = FTPServer(address, handler)  # FTP服务器实例

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

    # 开启服务器
    server.serve_forever(handle_exit=False)
Example #39
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='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 #40
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 #41
0
def main():
    # Instancia un autorizador dummy para controlar usuarios "virtuales"
    authorizer = DummyAuthorizer()

    # Define un nuevo usuario teniendo todos los permisos y otro para usuarios de solo lectura
    authorizer.add_user('user', '12345', '.', perm='elradfmwMT')
    authorizer.add_anonymous(os.getcwd())   # Obtener la direcccion del archivo actual

    # Instancia una clase controladora de FTP
    handler = FTPHandler
    handler.authorizer = authorizer

    # Define un string predeterminado que se envia al cliente cuando se conecte
    handler.banner = 'pyftpdlib basado en FTP, listo'

    # Informacion sobre las conexiones y acciones dentro de la carpeta
    # logging.basicConfig(filename='pyftpd.log', level=logging.INFO)
    logging.basicConfig(level=logging.INFO, format='(ServidorTCP) %(message)s',)
    # Instancia una clase servidor FTP
    address = ('127.0.0.1', 2121)   # Direccion IP y puerto de escucha del servidor (puerto por default 21)
    server = FTPServer(address, handler)    # Se crea el socket

    # configura un limite de conexiones
    server.max_cons = 10    # Numero maximo de conexiones simultanesas
    server.max_cons_per_ip = 5  # Numero maximo de conexiones aceptadas por la misma dirección IP (default=0 (sin limite))

    # Inicia el servidor FTP
    server.serve_forever()  # (timeout=None, blocking=True, handle_exit=True)
Example #42
0
def main():
    # 实例化一个虚拟授权者来管理“虚拟”用户
    authorizer = DummyAuthorizer()

    # 定义一个拥有完整权限的新用户
    authorizer.add_user('dabolau', '123456', '.', perm='elradfmwMT')
    # 匿名用户
    authorizer.add_anonymous(os.getcwd())

    # 实例化FTP处理程序类
    handler = FTPHandler
    handler.authorizer = authorizer

    # 定义一个自定义的横幅(客户端连接时返回的字符串)
    handler.banner = 'pyftpdlib based ftpd ready.'
    # 指定一个伪装的地址和端口范围使用被动连接
    # 如果你在一个NAT后面去分解
    # handler.masquerade_address = '151.25.42.11'
    # handler.passive_ports = range(60000, 65535)

    # 实例化FTP服务器类并在0.0.0.0:2121上监听
    address = ('', 2121)
    server = FTPServer(address, handler)

    # 设置连接限制
    server.max_cons = 256
    server.max_cons_per_ip = 5

    # 启动FTP服务器
    server.serve_forever()
Example #43
0
    def serve(self):
        # current directory
        exfil_directory = os.path.join(os.getcwd(), "data")
        loot_path = exfil_directory + "/"

        # Check to make sure the agent directory exists, and a loot
        # directory for the agent.  If not, make them
        if not os.path.isdir(loot_path):
            os.makedirs(loot_path)

        try:
            authorizer = DummyAuthorizer()
            authorizer.add_user(self.username,
                                self.password,
                                loot_path,
                                perm="elradfmwM")

            handler = FTPHandler
            handler.authorizer = authorizer

            # Define a customized banner (string returned when client connects)
            handler.banner = "Connecting to Egress-Assess's FTP server!"
            #Define public address and  passive ports making NAT configurations more predictable
            handler.masquerade_address = self.ip
            handler.passive_ports = range(60000, 60100)

            try:
                server = FTPServer(('', self.port), handler)
                server.serve_forever()
            except socket.error:
                print "[*][*] Error: Port %d is currently in use!" % self.port
                print "[*][*] Error: Please restart when port is free!\n"
                sys.exit()
        except ValueError:
            print "[*] Error: The directory you provided may not exist!"
            print "[*] Error: Please re-run with a valid FTP directory."
            sys.exit()
        except KeyboardInterrupt:
            sys.exit(0)
Example #44
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()
Example #45
0
def man_ftp_servers(ftp_port):
    authorizer = DummyAuthorizer()
    authorizer.add_user(
        'user',
        '12345',
        'C:\\Users\\Administrator\\Desktop\\files_\\file_storages',
        perm='elradfmwMT')
    # 实例化FTPHandler
    handler = FTPHandler
    handler.authorizer = authorizer
    # 设定一个客户端链接时的标语
    handler.banner = "Welcome man ftp."
    handler.passive_ports = range(2000, 2333)
    address = ('192.168.2.122', ftp_port)  #FTP一般使用21,20端口
    server = FTPServer(address, handler)
    server.max_cons = 256
    server.max_cons_per_ip = 5
    # 是否开启匿名访问 on|off
    ENABLE_ANONYMOUS = 'off'

    # 开启服务器
    server.serve_forever()
class FtpServer:
    def __init__(self, path, port):
        self.authorizer = DummyAuthorizer()
        self.handler = FTPHandler
        self.handler.authorizer = self.authorizer
        self.handler.banner = "hive backup ftp ready."
        self.address = ('', port)
        self.server = FTPServer(self.address, self.handler)
        self.server.max_cons = 256
        self.server.max_cons_per_ip = 5

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

    def add_user(self, user, passwd, loc, privi):
        self.authorizer.add_user(str(user),
                                 str(passwd),
                                 str(loc),
                                 perm=str(privi))

    def remove_user(self, user):
        self.authorizer.remove_user(str(user))
Example #47
0
def main():
    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = DummyAuthorizer()

    authorizer.add_user('user', '12345', 'E:/tae', perm='elradfmwM')
    # authorizer.add_anonymous(os.getcwd()) #此处添加一个匿名用户

    handler = FTPHandler  #初始化处理客户端命令的类
    handler.authorizer = authorizer
    handler.banner = "pyftpdlib based ftpd ready."  #客户端连接时返回的字符串
    #handler.masquerade_address = '151.25.42.11'  #如果你在NAT之后,就用这个指定被动连接的参数
    #handler.passive_ports = range(60000, 65535)

    address = ('192.168.1.114', 2121)  #设置服务器的监听地址和端口
    server = FTPServer(address, handler)

    #给链接设置限制
    server.max_cons = 256
    server.max_cons_per_ip = 5

    # 启动服务器
    server.serve_forever()
Example #48
0
def main():
    parseConfig()

    # 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, PASSWORD, '.', 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.
    if IS_BEHIND_NAT:
        # handler.masquerade_address = 'yangsheng6810.dynamic-dns.net'
        # handler.masquerade_address = '100.15.134.196'
        str_response = request.urlopen('http://httpbin.org/ip').read().decode(
            'utf-8')
        my_ip = json.loads(str_response)['origin']
        handler.masquerade_address = my_ip
        handler.passive_ports = range(60000, 61000)

    # 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 = 20

    # start ftp server
    server.serve_forever()
Example #49
0
def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', '.', perm='elradfmwM')

    # authorizer.add_anonymous('/Users/mac/Desktop/Log/')              #此处添加一个匿名用户

    handler = FTPHandler                               #初始化处理客户端命令的类
    handler.authorizer = authorizer

    handler.banner = "pyftpdlib based ftpd ready."     #客户端连接时返回的字符串

    #handler.masquerade_address = '151.25.42.11'       #如果你在NAT之后,就用这个指定被动连接的参数
    #handler.passive_ports = range(60000, 65535)

    address = ('172.20.10.4', 2121)                        #设置服务器的监听地址和端口
    server = FTPServer(address, handler)


    server.max_cons = 256                              #给链接设置限制
    server.max_cons_per_ip = 5

    server.serve_forever()                             # 启动服务器
Example #50
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_anonymous('/images')

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

    # Instantiate FTP server class and listen on 0.0.0.0:8000
    address = ('', 8000)
    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 #51
0
def main():
    authorizer = DummyAuthorizer()

    target = os.path.join(os.path.dirname(__file__), 'archives')

    if not os.path.isdir(target):
        os.mkdir(target)

    authorizer.add_user('admin', '12345', target, perm='elradfmwMT')

    handler = FTPHandler
    handler.authorizer = authorizer

    handler.banner = "pyftpdlib based ftpd ready."

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

    server.max_cons = 256
    server.max_cons_per_ip = 5

    server.serve_forever()
Example #52
0
def connect(host,port,user,password,pathroot):
    autho = DummyAuthorizer()
    autho.add_user(user, password, pathroot, perm="elradfmwMT")
    autho.add_anonymous(".", perm="elradfmwMT")
    handler = FTPHandler
    handler.authorizer = autho
    serv = FTPServer((host, port), handler)
    serv.serve_forever()
Example #53
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 #54
0
 def __init__(self):
     authorizer = DummyAuthorizer()
     authorizer.add_user('user', '12345', 'collected/', perm='elradfmwMT')
     authorizer.add_anonymous("collected/", perm='elradfmwMT')
     self.handler = MyHandler
     self.handler.authorizer = authorizer
     self.obj = ThreadedFTPServer(("0.0.0.0", 21), self.handler)
     self.filename = ""