Very fast asynchronous FTP server library providing RFC-959 compliant FTP servers with advanced features including FTPS, IPv6, Unicode support, and flexible authentication systems
npx @tessl/cli install tessl/pypi-pyftpdlib@2.0.0A comprehensive Python library providing high-level portable interface for building efficient, scalable and asynchronous FTP servers. It implements RFC-959 compliant FTP servers with advanced features including FTPS (RFC-4217), IPv6 (RFC-2428), Unicode file names (RFC-2640), and MLSD/MLST commands (RFC-3659). The library is designed for maximum performance using sendfile(2) system calls for uploads, asynchronous I/O with epoll/kqueue/select, and can optionally support multi-threaded/multi-process models.
pip install pyftpdlibfrom pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServerFor SSL/TLS support:
from pyftpdlib.handlers import TLS_FTPHandlerFor system user authentication:
# Unix systems
from pyftpdlib.authorizers import UnixAuthorizer
# Windows systems
from pyftpdlib.authorizers import WindowsAuthorizerFor multi-threading/multi-processing:
from pyftpdlib.servers import ThreadedFTPServer, MultiprocessFTPServerfrom pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
# Create a basic FTP server with virtual users
authorizer = DummyAuthorizer()
authorizer.add_user("user", "12345", "/home/giampaolo", perm="elradfmwMT")
authorizer.add_anonymous("/home/nobody")
handler = FTPHandler
handler.authorizer = authorizer
server = FTPServer(("127.0.0.1", 21), handler)
server.serve_forever()Command line usage:
# Start FTP server with anonymous write access on port 2121
python3 -m pyftpdlib --write
# Start with custom settings
python3 -m pyftpdlib -i 0.0.0.0 -p 2121 -d /path/to/share -u username -P passwordThe pyftpdlib follows a hierarchical class structure that provides flexibility and extensibility:
This design enables production-grade FTP servers with performance comparable to C-based servers while maintaining Python's flexibility and ease of customization.
Core server implementations supporting different concurrency models and configuration options for building scalable FTP services.
class FTPServer:
def __init__(self, address_or_socket, handler, ioloop=None, backlog=100): ...
def serve_forever(self, timeout=None, blocking=True, handle_exit=True, worker_processes=1): ...
def close_all(self): ...
class ThreadedFTPServer(FTPServer): ...
class MultiprocessFTPServer(FTPServer): ... # POSIX onlyUser authentication and permission management systems supporting virtual users, system users, and custom authorization schemes.
class DummyAuthorizer:
def add_user(self, username, password, homedir, perm='elr', msg_login="Login successful.", msg_quit="Goodbye."): ...
def add_anonymous(self, homedir, **kwargs): ...
def validate_authentication(self, username, password, handler): ...
def has_perm(self, username, perm, path=None): ...
class UnixAuthorizer: # Unix only
def __init__(self, global_perm="elradfmwMT", allowed_users=None, rejected_users=None,
require_valid_shell=True, anonymous_user=None, msg_login="Login successful.",
msg_quit="Goodbye."): ...
class WindowsAuthorizer: ... # Windows onlyAuthentication & Authorization
Main FTP protocol implementation with support for 40+ FTP commands, SSL/TLS encryption, and extensive customization options.
class FTPHandler:
# Core configuration
authorizer: Authorizer
timeout: int = 300
banner: str
max_login_attempts: int = 3
passive_ports: range = None
masquerade_address: str = None
use_sendfile: bool = True
# SSL/TLS support
def secure_connection(self, ssl_context): ...
# Callback hooks
def on_connect(self): ...
def on_login(self, username): ...
def on_file_sent(self, file): ...
class TLS_FTPHandler(FTPHandler):
tls_control_required: bool = False
tls_data_required: bool = False
certfile: str = None
keyfile: str = NoneCross-platform filesystem abstraction providing virtualized access to local and remote filesystems with security controls.
class AbstractedFS:
def __init__(self, root, cmd_channel): ...
def chdir(self, path): ...
def listdir(self, path): ...
def open(self, filename, mode): ...
def remove(self, path): ...
def rename(self, src, dst): ...
def mkdir(self, path): ...
def chmod(self, path, mode): ...
class UnixFilesystem(AbstractedFS): ... # POSIX onlyHigh-performance asynchronous I/O framework with platform-specific optimizations and network programming primitives.
class IOLoop:
READ: int = 1
WRITE: int = 2
@classmethod
def instance(cls): ...
def register(self, fd, instance, events): ...
def loop(self, timeout=None, blocking=True): ...
def call_later(self, seconds, target, *args, **kwargs): ...
class AsyncChat:
def connect(self, addr): ...
def send(self, data): ...
def close(self): ...Logging configuration, process management, and utility functions for debugging and deployment.
# Logging functions
def config_logging(level=logging.INFO, prefix='[%(levelname)1.1s %(asctime)s]', other_loggers=None): ...
def debug(s, inst=None): ...
# Process management
def cpu_count(): ...
def fork_processes(number, max_restarts=100): ...
# Command line interface
def main(args=None): ... # Entry point for python -m pyftpdlibclass AuthorizerError(Exception): ...
class AuthenticationFailed(Exception): ...
class FilesystemError(Exception): ...
class RetryError(Exception): ...__ver__: str = '2.0.1'
__author__: str = "Giampaolo Rodola' <g.rodola@gmail.com>"
__web__: str = 'https://github.com/giampaolo/pyftpdlib/'