Example Path: examples/FTP/FTPD_ExposeHtml
FTPD HTML Expose Application
Overview
This application creates a read-only FTP server that exposes HTML files from an embedded system as a browsable file system. It's designed for embedded systems using a network stack and provides both web server functionality and FTP access to HTML content.
The home page also lists every exposed file as clickable HTTP links (generated on the device from the same directory tree the FTP server reports), so the files can be browsed in any modern browser. This matters because browsers removed built-in ftp:// support around 2021 - the HTTP list and an FTP client (e.g. FileZilla) can be opened side by side to compare the two views.
- Note
- For FTP and SFTP using the EFFS file systesms, refer to examples in the \nburn\examples\EFFS folder
Features
- FTP Server: Runs on port 21 with read-only access to HTML files
- Web Server: HTTP server running on port 80
- Network Integration: Uses DHCP for automatic IP configuration
- File System Emulation: Creates a virtual directory tree from compiled HTML files
- Cross-Platform Access: Files accessible via web browsers and FTP clients
Application Components
Core Functionality
The application initializes a network stack and starts two main services:
- HTTP Web Server - Provides web-based access and status information
- FTP Server - Exposes HTML files as a read-only file system
File System Structure
The application builds a virtual file system from HTML files that are compiled into the application:
- Creates a tree structure with directories and files
- Supports nested directory hierarchies
- File metadata includes size and basic permissions
- Directory navigation follows standard FTP conventions
Key Functions
Network Services
- UserMain() - Main application entry point, initializes services
- webListFiles() - Renders the exposed file tree as a browsable list of HTTP links on the web page
Directory Tree Management
- BuildDirTree() - Constructs file system tree from HTML data
- GetDir() - Locates directories in the virtual file system
- getDirString() - Formats file/directory information for FTP clients
FTP Server Callbacks
Usage
Accessing Files
- Via Web Browser (HTTP): Navigate to the device's IP address. The home page lists every exposed file as a clickable link served over HTTP - works in any modern browser, no client needed.
- Via FTP Client: Connect to ftp://[device-ip] with an FTP client such as FileZilla. The same files appear, so the HTTP and FTP views can be compared directly.
- Browser FTP (deprecated): ftp:// links no longer open in Chrome, Firefox, or Edge (support removed ~2021). Use the HTTP list or an FTP client instead.
Browser Compatibility
Starting in 2020, some web browsers have begun blocking direct FTP access. In such cases:
- Use dedicated FTP client applications such as FileZilla
- Access files through the web server interface instead
Authentication
The current implementation accepts all FTP connections without password verification. For production use, implement proper authentication in FTPDSessionStart().
Technical Details
Dependencies
Memory Management
- Dynamic allocation for directory and file structures
- Linked list implementation for file system hierarchy
- Cleanup handled automatically on application termination
Configuration
- FTP Server Port: 21
- HTTP Server Port: 80 (default)
- Task Priority: MAIN_PRIO - 1 (higher than main task)
- Network Timeout: 5 seconds for DHCP
Read-Only Operations
The following FTP operations are supported:
- Directory listing (LIST, NLST)
- File download (RETR)
- Directory navigation (CWD, PWD)
- File existence checking
Unsupported Operations
These FTP operations always return failure:
- File upload (STOR)
- File deletion (DELE)
- Directory creation (MKD)
- Directory deletion (RMD)
- File renaming (RNFR/RNTO)
System Requirements
- Embedded system with network capability
- Network stack supporting TCP/IP
- Sufficient RAM for file system tree structure
- HTML files compiled into application data
Development Notes
This is an advanced application requiring knowledge of:
- FTP protocol implementation
- Embedded network programming
- File system navigation concepts
- HTML file management in embedded systems
The complexity primarily involves managing virtual directory structures and handling FTP client requests for file navigation and display.
Status Output
The application provides diagnostic information via serial port:
- Network initialization status
- FTP server startup confirmation
- IP address assignment
- Session start/end notifications
- System diagnostics (should be disabled for production)
Example Output
Started FTP Server
You can use a web browser to view files at URL "ftp://192.168.1.100"
Building the tree...
Ending session 1