Beispiel #1
0
def makeService(options):
    """
    Makes a new swftp-ftp service. The only option is the config file
    location. See CONFIG_DEFAULTS for list of configuration options.
    """
    from twisted.protocols.ftp import FTPFactory
    from twisted.cred.portal import Portal

    from swftp.ftp.server import SwftpFTPProtocol
    from swftp.realm import SwftpRealm
    from swftp.auth import SwiftBasedAuthDB
    from swftp.utils import (log_runtime_info, GLOBAL_METRICS,
                             parse_key_value_config)

    print('Starting SwFTP-ftp %s' % VERSION)

    c = get_config(options['config_file'], options)
    ftp_service = service.MultiService()

    # Add statsd service
    if c.get('ftp', 'log_statsd_host'):
        try:
            from swftp.statsd import makeService as makeStatsdService
            makeStatsdService(
                c.get('ftp', 'log_statsd_host'),
                c.getint('ftp', 'log_statsd_port'),
                sample_rate=c.getfloat('ftp', 'log_statsd_sample_rate'),
                prefix=c.get(
                    'ftp',
                    'log_statsd_metric_prefix')).setServiceParent(ftp_service)
        except ImportError:
            sys.stderr.write('Missing Statsd Module. Requires "txstatsd" \n')

    if c.get('ftp', 'stats_host'):
        from swftp.report import makeService as makeReportService
        known_fields = [
            'command.login',
            'command.logout',
            'command.makeDirectory',
            'command.removeDirectory',
            'command.removeFile',
            'command.rename',
            'command.access',
            'command.stat',
            'command.list',
            'command.openForReading',
            'command.openForWriting',
        ] + GLOBAL_METRICS
        makeReportService(
            c.get('ftp', 'stats_host'),
            c.getint('ftp', 'stats_port'),
            known_fields=known_fields).setServiceParent(ftp_service)

    authdb = SwiftBasedAuthDB(
        c.get('ftp', 'auth_url'),
        global_max_concurrency=c.getint('ftp', 'num_persistent_connections'),
        max_concurrency=c.getint('ftp', 'num_connections_per_session'),
        timeout=c.getint('ftp', 'connection_timeout'),
        extra_headers=parse_key_value_config(c.get('ftp', 'extra_headers')),
        verbose=c.getboolean('ftp', 'verbose'),
        rewrite_scheme=c.get('ftp', 'rewrite_storage_scheme'),
        rewrite_netloc=c.get('ftp', 'rewrite_storage_netloc'),
    )

    ftpportal = Portal(SwftpRealm())
    ftpportal.registerChecker(authdb)
    ftpfactory = FTPFactory(ftpportal)
    protocol = SwftpFTPProtocol
    protocol.maxConnectionsPerUser = c.getint('ftp', 'sessions_per_user')
    ftpfactory.protocol = protocol
    ftpfactory.welcomeMessage = c.get('ftp', 'welcome_message')
    ftpfactory.allowAnonymous = False
    ftpfactory.timeOut = c.getint('ftp', 'session_timeout')

    signal.signal(signal.SIGUSR1, log_runtime_info)
    signal.signal(signal.SIGUSR2, log_runtime_info)

    internet.TCPServer(c.getint('ftp', 'port'),
                       ftpfactory,
                       interface=c.get('ftp',
                                       'host')).setServiceParent(ftp_service)
    return ftp_service
Beispiel #2
0
def makeService(options):
    """
    Makes a new swftp-ftp service. The only option is the config file
    location. See CONFIG_DEFAULTS for list of configuration options.
    """
    from twisted.protocols.ftp import FTPFactory
    from twisted.cred.portal import Portal

    from swftp.ftp.server import SwftpFTPProtocol
    from swftp.realm import SwftpRealm
    from swftp.auth import SwiftBasedAuthDB
    from swftp.utils import (
        log_runtime_info, GLOBAL_METRICS, parse_key_value_config)

    print('Starting SwFTP-ftp %s' % VERSION)

    c = get_config(options['config_file'], options)
    ftp_service = service.MultiService()

    # Add statsd service
    if c.get('ftp', 'log_statsd_host'):
        try:
            from swftp.statsd import makeService as makeStatsdService
            makeStatsdService(
                c.get('ftp', 'log_statsd_host'),
                c.getint('ftp', 'log_statsd_port'),
                sample_rate=c.getfloat('ftp', 'log_statsd_sample_rate'),
                prefix=c.get('ftp', 'log_statsd_metric_prefix')
            ).setServiceParent(ftp_service)
        except ImportError:
            sys.stderr.write('Missing Statsd Module. Requires "txstatsd" \n')

    if c.get('ftp', 'stats_host'):
        from swftp.report import makeService as makeReportService
        known_fields = [
            'command.login',
            'command.logout',
            'command.makeDirectory',
            'command.removeDirectory',
            'command.removeFile',
            'command.rename',
            'command.access',
            'command.stat',
            'command.list',
            'command.openForReading',
            'command.openForWriting',
        ] + GLOBAL_METRICS
        makeReportService(
            c.get('ftp', 'stats_host'),
            c.getint('ftp', 'stats_port'),
            known_fields=known_fields
        ).setServiceParent(ftp_service)

    authdb = SwiftBasedAuthDB(
        c.get('ftp', 'auth_url'),
        global_max_concurrency=c.getint('ftp', 'num_persistent_connections'),
        max_concurrency=c.getint('ftp', 'num_connections_per_session'),
        timeout=c.getint('ftp', 'connection_timeout'),
        extra_headers=parse_key_value_config(c.get('ftp', 'extra_headers')),
        verbose=c.getboolean('ftp', 'verbose'),
        rewrite_scheme=c.get('ftp', 'rewrite_storage_scheme'),
        rewrite_netloc=c.get('ftp', 'rewrite_storage_netloc'),
    )

    ftpportal = Portal(SwftpRealm())
    ftpportal.registerChecker(authdb)
    ftpfactory = FTPFactory(ftpportal)
    protocol = SwftpFTPProtocol
    protocol.maxConnectionsPerUser = c.getint('ftp', 'sessions_per_user')
    ftpfactory.protocol = protocol
    ftpfactory.welcomeMessage = c.get('ftp', 'welcome_message')
    ftpfactory.allowAnonymous = False
    ftpfactory.timeOut = c.getint('ftp', 'session_timeout')

    signal.signal(signal.SIGUSR1, log_runtime_info)
    signal.signal(signal.SIGUSR2, log_runtime_info)

    internet.TCPServer(
        c.getint('ftp', 'port'),
        ftpfactory,
        interface=c.get('ftp', 'host')).setServiceParent(ftp_service)
    return ftp_service
Beispiel #3
0
#!/usr/bin/env python2
from __future__ import absolute_import, division, print_function

from os.path import isdir
from twisted.cred.checkers import AllowAnonymousAccess
from twisted.cred.portal import Portal
from twisted.internet import reactor
# ftp server imports
from twisted.protocols.ftp import FTPFactory, FTPRealm

from evora.common import netconsts

# TODO: this needs to be specified some other way
# Does not exist on non-observatory computers
data_path = "/home/mro/storage/evora_data/"

if isdir(data_path):
    p = Portal(FTPRealm(data_path), [AllowAnonymousAccess()])
    f = FTPFactory(p)
    f.timeOut = None
    reactor.listenTCP(netconsts.FTP_TRANSFER_PORT, f)
else:
    print("[ftp_server.py] Directory at '" + data_path +
          "' does not exist, exiting...")
    quit()

reactor.run()