How rakshithvk19/rax-ftp-server works
Project type and purpose
• This is a systems-level, networked FTP server written in Rust, implementing core RFC 959 commands. It’s not a front-end/backend web app but an open-source command-line server demonstrating TCP networking, multi-threading, modular design, and Rust skills.
File structure
• Top-level:
• src/main.rs – application entrypoint, logging setup, starts the server
• src/server.rs – listens on TCP port 2121, accepts control connections, spawns client threads
• src/client.rs & src/client_handler.rs – per-client state (authenticated user, CWD, data ports) and thread logic
• src/commands/ – parser.rs (parses raw FTP commands), handlers.rs (executes them), utils.rs (shared helpers)
• src/data_channel.rs – establishes active (PORT) or passive (PASV) data connections
• src/file_transfer.rs – implements STOR, RETR, LIST over data channels
• src/auth.rs – USER/PASS/LOGOUT logic
• src/utils.rs – common helpers (e.g., IP validation, path normalization)
• tests/integration.rs – end-to-end command parsing and server behavior
Readme insights
• The README confirms: single control listener, multi-threaded client handling via std::thread + Arc<Mutex<HashMap>> for shared client tracking, logging via log/env_logger, and core FTP commands (STOR, RETR, LIST, CWD, PWD, etc.)
Main components
a. Control Connection Listener
• TCP Listener on 127.0.0.1:2121 (src/server.rs)
b. Thread Manager / Client Thread
• On accept, spawn a thread, wrap shared state in Arc<Mutex<HashMap<ClientID,ClientState>>>
• Instantiate ClientHandler (src/client_handler.rs) to manage session
c. Authentication Module (src/auth.rs)
• Handles USER, PASS, LOGOUT, updates ClientState
d. Command Parser (src/commands/parser.rs)
• Parses incoming lines into FTPCommand enums
e. Command Handlers (src/commands/handlers.rs)
• Routes commands to auth, file transfer, directory management, session management
f. Data Channel Manager (src/data_channel.rs)
• Active (PORT) & Passive (PASV) modes: negotiates and opens data sockets
g. File Transfer Module (src/file_transfer.rs)
• Implements STOR, RETR, LIST, reading/writing local filesystem
h. Directory Navigation (via handlers + utils.rs)
• CWD, PWD, validating paths
i. Shared ClientState Store
• Arc<Mutex<HashMap>> tracking each client’s IP, auth status, working dir, data port
j. Logging Subsystem
• log crate + env_logger: logs command receipt, transfers, errors
Relationships and interactions
• External FTP Client → TCP 2121 → Server Listener
• Listener → spawns Thread → ClientHandler
• ClientHandler loops: read TCP control → Parser → Command Handler
• Handler may call Auth, Data Channel, File Transfer, Directory modules
• Data operations open secondary TCP sockets → transfer with client
• All modules write to shared ClientState and to logs
Architectural patterns & design principles
• Modular separation: auth, parser, handlers, data, transfer
• Multi-threading with shared Mutex state for concurrency control
• Single responsibility per module, clear crate boundaries
• Synchronous/blocking I/O (std::net, std::thread), clear future async scope
Technologies, frameworks, libraries
• Rust 2021 edition, Cargo
• std::net::TcpListener / TcpStream
• std::thread, std::sync::{Arc,Mutex}
• log + env_logger for tracing
• telnet / netcat only for testing
Essential elements
• Shared state store with mutex annotation
• Logging subsystem as a side component that all modules call into