MockForge FTP
FTP protocol support for MockForge.
This crate provides FTP-specific functionality for creating mock FTP servers, including virtual file systems, fixture-driven responses, and file transfer simulation. Perfect for testing FTP clients, file upload workflows, and FTP-based integrations.
Features
- FTP Server Mocking: Full FTP protocol support with standard commands
- Virtual File System: In-memory file storage with configurable content
- Fixture Management: YAML-based configuration for file structures
- Upload Handling: Configurable validation and storage for file uploads
- Template Support: Dynamic content generation using Handlebars templates
- Protocol Compliance: Supports passive/active modes and authentication
Quick Start
Basic FTP Server
use FtpServer;
use FtpConfig;
async
Server with Custom Configuration
use FtpConfig;
use FtpServer;
let config = FtpConfig ;
let server = new.await?;
server.start.await?;
Virtual File System
MockForge FTP includes a powerful virtual file system for creating realistic file structures:
Static Files
use ;
use PathBuf;
let mut vfs = new;
// Add a static file
let content = Static;
let metadata = FileMetadata ;
let file = new;
vfs.add_file?;
Generated Files
use ;
// Generate a 1MB file with random content
let content = Generated ;
// Generate a file with incremental bytes (0, 1, 2, ...)
let incremental = Generated ;
Template Files
use FileContent;
// Use Handlebars templates for dynamic content
let content = Template;
Fixture System
Define complete FTP server configurations using YAML fixtures:
identifier: "test-server"
name: "Test FTP Server"
description: "A test FTP server with sample files"
virtual_files:
- path: "/welcome.txt"
content:
type: "static"
content: "Welcome to MockForge FTP!"
permissions: "644"
owner: "ftp"
group: "ftp"
- path: "/data.bin"
content:
type: "generated"
size: 1048576 # 1MB
pattern: "random"
permissions: "644"
owner: "ftp"
group: "ftp"
upload_rules:
- path_pattern: "/uploads/.*\\.txt"
auto_accept: true
validation:
max_size_bytes: 1048576 # 1MB limit
allowed_extensions:
storage:
type: "memory"
- path_pattern: "/logs/.*\\.log"
auto_accept: true
storage:
type: "file"
path: "/tmp/ftp_logs"
Loading Fixtures
use ;
use FtpConfig;
let config = default;
let server = new.await?;
// Load fixture from file
server.spec_registry.load_fixture_from_file.await?;
// Or create fixture programmatically
use ;
let fixture = FtpFixture ;
server.spec_registry.add_fixture?;
Upload Handling
Configure how the server handles file uploads:
Upload Rules
use ;
use Regex;
let rule = UploadRule ;
Storage Options
- Memory: Store uploaded files in the virtual file system
- File: Write to the local file system
- Discard: Accept uploads but don't store them
FTP Protocol Support
MockForge FTP supports standard FTP commands:
- Connection: USER, PASS, QUIT
- Navigation: CWD, CDUP, PWD
- Directory: LIST, NLST, MKD, RMD
- File Operations: RETR, STOR, DELE, RNFR/RNTO
- System: SYST, FEAT, OPTS
- Transfer Modes: Passive and active mode support
Testing FTP Clients
Use MockForge FTP to test FTP client applications:
use FtpStream; // FTP client library
use FtpServer;
use FtpConfig;
use task;
async
Configuration
FtpConfig
use FtpConfig;
let config = FtpConfig ;
Integration with MockForge
MockForge FTP integrates seamlessly with the MockForge ecosystem:
- MockForge Core: Shared configuration and logging
- MockForge CLI: Command-line interface for FTP server management
- MockForge Plugins: Extend FTP functionality with custom plugins
Performance
MockForge FTP is optimized for testing scenarios:
- In-Memory Storage: Fast file operations without disk I/O
- Lazy Content Generation: Files generated on-demand
- Concurrent Connections: Handle multiple simultaneous FTP clients
- Low Memory Footprint: Efficient storage for large file simulations
Examples
See the examples directory for complete working examples including:
- Basic FTP server setup
- Fixture-driven configurations
- Upload handling scenarios
- Integration testing patterns
Related Crates
mockforge-core: Core mocking functionalitylibunftp: Underlying FTP server implementationsuppaftp: FTP client for testing
License
Licensed under MIT OR Apache-2.0