本文整理汇总了Python中pyftpdlib.servers.FTPServer.max_cons方法的典型用法代码示例。如果您正苦于以下问题:Python FTPServer.max_cons方法的具体用法?Python FTPServer.max_cons怎么用?Python FTPServer.max_cons使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyftpdlib.servers.FTPServer
的用法示例。
在下文中一共展示了FTPServer.max_cons方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
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()
示例2: custom_server
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
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)
示例3: server_start
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
def server_start(is_verbose=False, port=None):
if not os.path.isfile('conf.json'):
print 'Conf file not found, please run setup.'
sys.exit(1)
with open('conf.json') as jd:
template = json.load(jd)
container.set_acc_db(str(template['user_db']), str(template['user_table']))
container.set_shares_db(str(template['user_logs']))
container.set_root_dir(str(template['root']))
container.set_log_file(str(template['root']) + '/pyftpd.log')
auth = authorizer()
handle = handler
handle.user_sendfile = True
handle.timeout = None
handle.authorizer = auth
handle.banner = 'this is the banner'
if port: # untested
address = ('', 1024)
else:
address = ('', 21)
server = FTPServer(address, handle)
server.max_cons = 256
server.maxcons_per_ip = 1000000
if not is_verbose:
logging.basicConfig(filename=container.get_log_file(), level=logging.INFO)
server.serve_forever()
示例4: main
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
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()
示例5: start_ftp_server
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
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))
示例6: run
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
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()
示例7: run
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
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()
示例8: main
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
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="welcome", 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()
示例9: main
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
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()
示例10: main
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
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()
示例11: main
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
def main():
##
#authorizer = WindowsAuthorizer()
## Use Guest user with empty password to handle anonymous sessions.
## Guest user must be enabled first, empty password set and profile
## directory specified.
##authorizer = WindowsAuthorizer(anonymous_user="Guest", anonymous_password="")
#handler = FTPHandler
#handler.authorizer = authorizer
#ftpd = FTPServer(('', 21), handler)
#ftpd.serve_forever()
#return
####################
# 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())
#authorizer.add_user('addons', 'road', os.getcwd(), perm='elradfmwM')
#authorizer.add_user('addons', 'road', xbmc.translatePath("F:\zzz__AppData\XBMC\portable_data\addons"), perm='elradfmwM')
#authorizer.add_anonymous(xbmc.translatePath("F:\zzz__AppData\XBMC\portable_data\addons"))
#path01=xbmc.translatePath("F:\\zzz__AppData\\XBMC\\portable_data\\addons\\")
path01=xbmc.translatePath("F:\\zzz__AppData\\XBMC\\portable_data\\addons\\")
path01=path01.replace("\\","|tag|").replace("|tag|","\\\\")
#path01=path01.replace(os.sep,"|tag|").replace("|tag|","\\\\")
#authorizer.add_anonymous(path01)
authorizer.add_user('addons', 'xbmchub', path01, perm='elradfmwM')
# 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()
示例12: server_start_testing
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
def server_start_testing(is_verbose=False, port=None):
user_db = 'test_users.db'
user_table = 'users'
shares_db = 'test_shares.db'
username = 'admin'
password = 'admin'
root = os.getcwd() + '/test_server'
if os.path.isfile(user_db):
os.remove(user_db)
if os.path.isfile(shares_db):
os.remove(shares_db)
if os.path.isdir(root):
rmtree(root)
os.mkdir(root)
ta = TableAdder(user_db, user_table)
cols = ['name', 'status', 'password', 'salt', 'welcome', 'goodbye']
for col in cols:
if col == 'status':
ta.add_column(col, 'integer')
else:
ta.add_column(col)
ta.commit()
del ta
with TableManager(user_db, user_table) as tm:
salt = gen_salt()
password = gen_hash(password, salt)
row = [username, 1, password, salt, 'welcome', 'goodbye']
tm.quick_push(row)
ta = TableAdder(shares_db, username)
cols = ['time', 'ip', 'cmd', 'line', 'arg']
for col in cols:
ta.add_column(col)
ta.commit()
del ta
container.set_acc_db(user_db, user_table)
container.set_shares_db(shares_db)
container.set_root_dir(root)
container.set_log_file(root + '/pyftpd.log')
auth = authorizer()
handle = handler
handle.user_sendfile = True
handle.timeout = None
handle.authorizer = auth
handle.banner = 'this is the banner'
if port: # untested
address = ('', port)
else:
address = ('', 21)
server = FTPServer(address, handle)
server.max_cons = 256
server.maxcons_per_ip = 5
if not is_verbose:
logging.basicConfig(filename=container.get_log_file(), level=logging.INFO)
server.serve_forever()
示例13: main
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
def main():
# Parse cmdline
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-c", "--conf", help="configuration file", default="config.json")
parser.add_argument("-r", "--root", help="root dir", default="./")
parser.add_argument("-p", "--port", help="listen port", type=int)
flag = parser.parse_args()
print flag
# Load configuration
cfg = json.load(open(flag.conf, "rb"))
# Instantiate a dummy authorizer for managing 'virtual' users
authorizer = DummyAuthorizer()
# Define a new user having full r/w permissions and a read-only
perm = "elradfmwM"
for acl in cfg.get("acls", []):
print flag.root
base_dir = os.path.join(flag.root, acl.get("directory", "./").lstrip("/"))
print base_dir
authorizer.add_user(acl["username"], acl["password"], base_dir, perm=perm)
# anonymous user
if cfg.get("anonymous"):
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 = cfg.get("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 = ("", flag.port or cfg.get("port", 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()
示例14: main
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
def main():
authorizer = DummyAuthorizer()
authorizer.add_user('admin', 'admin123', '/srv/ftp', perm='elradfmwM')
authorizer.add_user('student', 'student123', '/srv/ftp/student', perm='elr')
#authorizer.add_anonymous('/tmp')
handler = FTPHandler
handler.authorizer = authorizer
handler.passive_ports = range(44400, 44499)
handler.banner = "welcome to chenfy's ftp server~"
server = FTPServer(('0.0.0.0', 8888), handler)
server.max_cons = 10
server.max_cons_per_ip = 5
server.serve_forever()
示例15: startServer
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import max_cons [as 别名]
def startServer():
authorizer = DummyAuthorizer() # create a new FTP authorizer
authorizer.add_anonymous(USER_HOME + "/anonymous", perm='elradfmwM') # add anonymous user, set the directory for anonymous file uploads and give enough permissions to the anonymous user
# permissions are denoted by the charactors 'elradfmwM'. To see what they means please visit, https://code.google.com/p/pyftpdlib/wiki/Tutorial
handler = MyHandler # select the created custom FTP hander
handler.authorizer = authorizer # assign the authorizer to the handler
handler.banner = "Server Ready.." # server banner is returned when the client calls a getWelcomeMessage() call
hostname = "" # hostname is empty, which implies all interfaces (0.0.0.0)
address = (hostname,21)
server = FTPServer(address, handler) # start listening on port 21 on all interfaces
server.max_cons = 10 # maximum number of simultanious connections per time
server.serve_forever() # start the server