MCPcopy
hub / github.com/giampaolo/pyftpdlib / main

Function main

pyftpdlib/__main__.py:345–424  ·  view source on GitHub ↗

Start a standalone anonymous FTP server.

(args=None)

Source from the content-addressed store, hash-verified

343
344
345def main(args=None):
346 """Start a standalone anonymous FTP server."""
347 opts = parse_args(args=args)
348
349 if opts.debug:
350 config_logging(level=logging.DEBUG)
351
352 # On recent Windows versions, if address is not specified and IPv6
353 # is installed the socket will listen on IPv6 by default; in this
354 # case we force IPv4 instead.
355 if os.name in ("nt", "ce") and not opts.interface:
356 opts.interface = "0.0.0.0"
357
358 authorizer = DummyAuthorizer()
359 perm = "elradfmwMT" if opts.write else "elr"
360 if opts.username:
361 if not opts.password:
362 raise argparse.ArgumentTypeError(
363 "if username (-u) is supplied, password (-P) is required"
364 )
365 authorizer.add_user(
366 opts.username, opts.password, opts.directory, perm=perm
367 )
368 else:
369 authorizer.add_anonymous(opts.directory, perm=perm)
370
371 # FTP or FTPS?
372 if opts.tls:
373 if TLS_FTPHandler is None:
374 raise argparse.ArgumentTypeError("PyOpenSSL not installed")
375 if not opts.certfile or not opts.keyfile:
376 raise argparse.ArgumentTypeError(
377 "--tls requires --keyfile and --certfile args"
378 )
379 handler = TLS_FTPHandler
380 handler.certfile = opts.certfile
381 handler.keyfile = opts.keyfile
382 if opts.tls_control_required:
383 handler.tls_control_required = True
384 if opts.tls_data_required:
385 handler.tls_data_required = True
386 else:
387 if opts.certfile or opts.keyfile:
388 raise argparse.ArgumentTypeError(
389 "--keyfile and --certfile args requires --tls arg"
390 )
391 handler = FTPHandler
392
393 # Configure handler.
394 handler.authorizer = authorizer
395 handler.masquerade_address = opts.nat_address
396 handler.passive_ports = opts.range
397 handler.timeout = opts.timeout
398 handler.dtp_handler.timeout = opts.timeout
399 handler.banner = opts.banner
400 handler.max_login_attempts = opts.max_login_attempts
401 handler.permit_foreign_addresses = opts.permit_foreign_addresses
402 handler.permit_privileged_ports = opts.permit_privileged_ports

Callers 15

test_interface_optMethod · 0.90
test_port_optMethod · 0.90
test_write_optMethod · 0.90
test_directory_optMethod · 0.90
test_nat_address_optMethod · 0.90
test_range_optMethod · 0.90
test_debug_optMethod · 0.90
test_concurrencyMethod · 0.90
test_timeoutMethod · 0.90
test_bannerMethod · 0.90

Calls 7

add_userMethod · 0.95
add_anonymousMethod · 0.95
parse_argsFunction · 0.85
config_loggingFunction · 0.85
DummyAuthorizerClass · 0.85
serve_foreverMethod · 0.45
close_allMethod · 0.45

Tested by 15

test_interface_optMethod · 0.72
test_port_optMethod · 0.72
test_write_optMethod · 0.72
test_directory_optMethod · 0.72
test_nat_address_optMethod · 0.72
test_range_optMethod · 0.72
test_debug_optMethod · 0.72
test_concurrencyMethod · 0.72
test_timeoutMethod · 0.72
test_bannerMethod · 0.72