本文整理汇总了Python中pyftpdlib.authorizers.DummyAuthorizer类的典型用法代码示例。如果您正苦于以下问题:Python DummyAuthorizer类的具体用法?Python DummyAuthorizer怎么用?Python DummyAuthorizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DummyAuthorizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
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)
示例2: run
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()
示例3: main
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()
示例4: __init__
def __init__(self, addr=None):
os.mkdir ('server')
os.chdir ('server')
try:
HOST = socket.gethostbyname ('localhost')
except socket.error:
HOST = 'localhost'
USER = '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 ('..')
示例5: ftp_server
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()
示例6: main
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()
示例7: main
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()
示例8: main
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()
示例9: start_ftp_server
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))
示例10: run
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()
示例11: main
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()
示例12: main
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()
示例13: main
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()
示例14: main
def main():
authorizer = DummyAuthorizer()
authorizer.add_user("user", "12345", ".")
handler = FTPHandler
handler.authorizer = authorizer
server = ThreadedFTPServer(("", 2121), handler)
server.serve_forever()
示例15: run_server
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)