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

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

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

    handler.banner = 'pyftpdlib based ftpd ready'

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

    server.max_conns=settings.maxconn
    server.max_conns_pre_ip=settings.maxconnperip
    
    server.serve_forever()
Beispiel #5
0
    def main_ftp(self):
        self.authorizer = DummyAuthorizer()

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

        handler = FTPHandler
        handler.authorizer = self.authorizer
        self.server = MultiprocessFTPServer((self.ip, self.port), handler)
        self.server.serve_forever(timeout=5)
Beispiel #6
0
def start_ftp_server(http_url, accounts, authentication_backends=(),
                     ssl_cert_path=None, http_basic_auth=False,
                     listen_host=None, listen_port=None, listen_fd=None,
                     passive_port_min=None, passive_port_max=None,
                     masquerade_address=None):

    if ssl_cert_path:

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

        handler = TLS_FTPHandler
        handler.dtp_handler = TLS_PostDTPHandler

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

    else:

        handler = FTPHandler
        handler.dtp_handler = PostDTPHandler

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

    if masquerade_address:
        handler.masquerade_address = masquerade_address

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

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

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

    server = MultiprocessFTPServer(listen, handler)
    server.max_cons = 256
    server.max_cons_per_ip = 5
    server.serve_forever()
Beispiel #7
0
def startftpServer(concurrytype):
    global server
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', '.')
    handler = FTPHandler
    handler.authorizer = authorizer
    if concurrytype == 'process':
        server = MultiprocessFTPServer(('', 2121), handler)
    elif concurrytype == 'thread':
        server = ThreadedFTPServer(('', 2121), handler)
    else:
        logger.info('Enter type mismatch')
    server.serve_forever()
Beispiel #8
0
def init_server_and_run(handler):
    address = ('0.0.0.0', 21)
    server = MultiprocessFTPServer(address, handler)
    # set a limit for connections
    server.max_cons = 2048
    server.max_cons_per_ip = 2048

    # start ftp server
    server.serve_forever()
    server.close_all()
Beispiel #9
0
class ftp_server:
    #Starts up FTP Server
    def __init__(self, ip='', port=2121, logs_from_pyftpdlib=False, anonymous_can_write=False):
        if not logs_from_pyftpdlib:
            ftp_log.LEVEL = ftp_log.logging.ERROR
        self._anonymous_can_write = anonymous_can_write
        self.ip = ip
        self.port = port

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

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

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

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

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

    def clean_up(self):
        self.server.close_all()
    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()
Beispiel #11
0
def main():
    # configuracao de log
    logger = logging.getLogger()
    ch = logging.StreamHandler(sys.stdout)
    logger.setLevel(logging.DEBUG)
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    # fim configuracao de log

    # usando os usuarios UNIX
    authorizer = UnixAuthorizer(rejected_users=["root"],
                                require_valid_shell=True)
    handler = FTPHandler
    handler.authorizer = authorizer
    handler.abstracted_fs = UnixFilesystem
    handler.log_prefix = "%(username)s@%(remote_ip)s"
    #logger.basicConfig(filename='/var/log/pyftpd.log', level=logging.INFO)
    # utilizando o servidor multiprocesso
    server = MultiprocessFTPServer(('', 21), handler)
    server.serve_forever()
        def tw_ftp_server():
            """ thread worker for the ftp server """
            authorizer = DummyAuthorizer()
            authorizer.add_user('user', '12345', ftp_root_dir, perm='elradfmwMT')

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

            # start ftp server
            while self._com_queue.empty():
                server.serve_forever(timeout=0.1, blocking=False)
            self._com_queue.get()
            server.close_all()
            time.sleep(1)
Beispiel #13
0
def start_ftp_server(http_url, accounts, authentication_backends=(),
                     ssl_cert_path=None, http_basic_auth=False,
                     listen_host=None, listen_port=None, listen_fd=None,
                     passive_port_min=None, passive_port_max=None,
                     masquerade_address=None):

    if ssl_cert_path:

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

        handler = TLS_FTPHandler
        handler.dtp_handler = TLS_PostDTPHandler

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

    else:

        handler = FTPHandler
        handler.dtp_handler = PostDTPHandler

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

    if masquerade_address:
        handler.masquerade_address = masquerade_address

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

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

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

    server = MultiprocessFTPServer(listen, handler)
    server.max_cons = 256
    server.max_cons_per_ip = 5
    server.serve_forever()
Beispiel #14
0
    def run_ftp(self,
                studentDirectory='./student/',
                teacherDirectory='./teacher'):
        """
        Runs a PyFTPlib FTP server to provide users with access to their task/answer documents.

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

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

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

        handler.banner = "DVNG tasks ftp server"

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

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

        # start ftp server
        print("Task sheets are available over ftp on port 21\n" +
              "\tUsername: %s\n" % ("teacher" if self.teacher else "student") +
              "\tPassword: %s\n" % pw +
              "Keep this terminal open until you've retreived your files.")
        logging.basicConfig(level=logging.CRITICAL)
        server.serve_forever()
Beispiel #15
0
def run(host='0.0.0.0', port=21, mode="single"):
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)  # Log等级总开关
    fh = logging.FileHandler(filename="ftpserver.log", encoding='utf-8')
    logger.addHandler(fh)

    ftp_authorizers = DummyMD5Authorizer()
    # 添加用户权限和路径,括号内的参数是(用户名,密码,用户目录,权限)
    """
    读取权限:
    "e" =更改目录(CWD,CDUP命令)
    "l" =列表文件(LIST,NLST,STAT,MLSD,MLST,SIZE命令)
    "r" =从服务器检索文件(RETR命令)
    写入权限:
    "a" =将数据附加到现有文件(APPE命令)
    "d" =删除文件或目录(DELE,RMD命令)
    "f" =重命名文件或目录(RNFR,RNTO命令)
    "m" =创建目录(MKD命令)
    "w" =将文件存储到服务器(STOR,STOU命令)
    "M"=更改文件模式/权限(SITE CHMOD命令)0.7.0中的新增功能
    "T"=更改文件修改时间(SITE MFMT命令)1.5.3中的新增功能
    """
    hash_password = hash_md5("12345")
    home_dir = os.getcwd()
    ftp_authorizers.add_user(username='******',
                             password=hash_password,
                             homedir=home_dir,
                             perm="elradfmwMT")
    # 添加匿名用户只需要指定路径
    ftp_authorizers.add_anonymous('/tmp/')

    # 初始化ftp句柄
    ftp_handler = MyFTPHandler
    ftp_handler.authorizer = ftp_authorizers

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

    # 添加被动端口范围
    ftp_handler.passive_ports = range(30000, 30100)

    # 下载上传速度设置, 0为无限制
    dtp_handler = ThrottledDTPHandler
    dtp_handler.read_limit = 300 * 1024  # 300kb/s
    dtp_handler.write_limit = 300 * 1024  # 300kb/s
    ftp_handler.dtp_handler = dtp_handler

    # 设置监听ip和端口,多线程模式
    if mode == "default":
        server = FTPServer((host, port), ftp_handler)
    elif mode == "threaded":
        server = ThreadedFTPServer((host, port), ftp_handler)
    elif mode == "multiprocess":
        server = MultiprocessFTPServer((host, port), ftp_handler)
    else:
        server = FTPServer((host, port), ftp_handler)

    # 设置最大连接数
    server.max_cons = 150
    server.max_cons_per_ip = 15

    # 开始服务,打印日志
    server.serve_forever()
Beispiel #16
0
if os.name == 'posix':
    authorizer = UnixAuthorizer()
# Trying to get Windows to work...
#elif os.name == 'nt':
#    authorizer = WindowsAuthorizer()
else:
    try:
        OperatingSystemError(
            print(
                "[WARN]: Your operating system isn't supported! This software runs only on Unix machines!"
            ))
    except OperatingSystemError:
        print("[WARN]: This shouldn't happen but alrighty then!")
        exitError(str(-1))
        sys.exit(0)

handler = FTPHandler
handler.authorizer = authorizer

while isRunning:

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

    if (Interrupt()):
        isRunning == False
        sys.exit(0)
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import MultiprocessFTPServer
import os

local = os.getcwd()
authorizer = DummyAuthorizer()
authorizer.add_user('user', '12345', '/home/adriandersonlira', perm='elradfmw')
authorizer.add_anonymous('/home/adriandersonlira', perm='elradfmw')

handler = FTPHandler
handler.authorizer = authorizer

server = MultiprocessFTPServer(('127.0.0.1', 1026), handler)
server.serve_forever()