or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authorizers.mdfilesystems.mdhandlers.mdindex.mdioloop.mdservers.mdutilities.md
tile.json

tessl/pypi-pyftpdlib

Very fast asynchronous FTP server library providing RFC-959 compliant FTP servers with advanced features including FTPS, IPv6, Unicode support, and flexible authentication systems

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pyftpdlib@2.0.x

To install, run

npx @tessl/cli install tessl/pypi-pyftpdlib@2.0.0

index.mddocs/

pyftpdlib

A 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.

Package Information

  • Package Name: pyftpdlib
  • Language: Python
  • Installation: pip install pyftpdlib

Core Imports

from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

For SSL/TLS support:

from pyftpdlib.handlers import TLS_FTPHandler

For system user authentication:

# Unix systems
from pyftpdlib.authorizers import UnixAuthorizer

# Windows systems  
from pyftpdlib.authorizers import WindowsAuthorizer

For multi-threading/multi-processing:

from pyftpdlib.servers import ThreadedFTPServer, MultiprocessFTPServer

Basic Usage

from 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 password

Architecture

The pyftpdlib follows a hierarchical class structure that provides flexibility and extensibility:

  • FTPServer: Accepts connections and dispatches them to handlers, with support for async, threaded, and multi-process models
  • FTPHandler: Main server-protocol-interpreter implementing 40+ FTP commands per RFC-959
  • Authorizers: Handle authentication and permissions for virtual users, Unix users, or Windows users
  • DTPHandler: Manages data transfer operations with support for active/passive modes and SSL/TLS
  • AbstractedFS: Cross-platform filesystem interface providing virtualized file system access

This design enables production-grade FTP servers with performance comparable to C-based servers while maintaining Python's flexibility and ease of customization.

Capabilities

FTP Servers

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 only

FTP Servers

Authentication & Authorization

User 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 only

Authentication & Authorization

FTP Protocol Handlers

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 = None

FTP Protocol Handlers

File System Interface

Cross-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 only

File System Interface

Async I/O Framework

High-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): ...

Async I/O Framework

Logging & Utilities

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 pyftpdlib

Logging & Utilities

Exception Classes

class AuthorizerError(Exception): ...
class AuthenticationFailed(Exception): ...
class FilesystemError(Exception): ...
class RetryError(Exception): ...

Constants

__ver__: str = '2.0.1'
__author__: str = "Giampaolo Rodola' <g.rodola@gmail.com>"
__web__: str = 'https://github.com/giampaolo/pyftpdlib/'