TFTP Client Application
Overview
This NetBurner TFTP Client example demonstrates how to use a NetBurner device to communicate with a TFTP (Trivial File Transfer Protocol) server for both file upload and download operations.
Features
- File Download: Retrieve files from a TFTP server using the
GetTFTP() function
- File Upload: Send files to a TFTP server using the
SendTFTP() function
- Configurable Server: Support for specifying TFTP server IP address
- Error Handling: Comprehensive error checking and timeout management
- Binary and Text Modes: Support for both binary ("b") and text ("t") transfer modes
Requirements
TFTP Server Configuration
- The TFTP server must be configured to handle both read and write operations
- Ensure the server allows file transfers in the directory where test files will be stored
NetBurner Device Configuration
The TFTP server address can be configured through multiple methods:
- NetBurner device's Configuration Server web interface
- Direct modification in the application code (currently set to
10.1.1.100)
- Serial Configuration Server of the device
- Application data flash memory using configuration parameters
Application Flow
Initialization
- Initialize the network stack
- Enable system diagnostics
- Start HTTP web server on default port 80
- Wait for DHCP address assignment (5-second timeout)
TFTP Operations
- File Upload Test: Creates a sample text file with 10 lines and uploads it as "tftp.txt"
- File Download Test: Downloads "tftp.txt" from the TFTP server
- Results Display: Shows operation results and data content
Code Structure
Key Functions
SendTFTP_Test()
- Creates sample data (10 lines of text)
- Uploads data to TFTP server as "tftp.txt"
- Handles upload results and error conditions
ReadTFTP_Test()
- Downloads "tftp.txt" from TFTP server
- Displays received data and byte count
- Handles download results and error conditions
UserMain()
- Main application entry point
- Performs initialization sequence
- Executes both send and receive tests
- Enters infinite loop after completion
Configuration Parameters
#define TFTP_SERVER_IP "10.1.1.100"
const int bufferSize = 1024;
TFTP Function Parameters
Both GetTFTP() and SendTFTP() functions use similar parameter structures:
- Filename: Name of file to transfer ("tftp.txt")
- Mode: Transfer mode - "b" for binary, "t" for text
- Buffer: Data buffer for transfer operations
- Length: Data length for transfers
- Timeouts: Operation and packet-level timeout values
- Server IP: TFTP server IP address
Return Codes
The application handles three main TFTP return codes:
- TFTP_OK: Operation completed successfully
- TFTP_TIMEOUT: Operation timed out
- TFTP_ERROR: Error occurred during operation
Usage Instructions
- Setup TFTP Server: Configure a TFTP server on your network with read/write permissions
- Configure IP Address: Update
TFTP_SERVER_IP to match your TFTP server's IP address
- Build and Deploy: Compile and deploy the application to your NetBurner device
- Network Connection: Ensure the NetBurner device is connected to the same network as the TFTP server
- Monitor Output: Use a serial terminal to view application output and results
- Reset to Repeat: Reset the device to run the test sequence again
Test Files
The application works with a test file named "tftp.txt":
- Upload Test: Creates and sends a file with 10 numbered lines
- Download Test: Retrieves the same file from the server
- Content Verification: Displays received data for verification
Network Requirements
- DHCP-enabled network for automatic IP assignment
- Network connectivity between NetBurner device and TFTP server
- TFTP server listening on standard port 69
- Firewall permissions for TFTP traffic
Troubleshooting
Common Issues
- Timeout Errors: Check network connectivity and TFTP server status
- Permission Errors: Verify TFTP server write permissions
- File Not Found: Ensure test file exists on server for download operations
- Network Issues: Confirm DHCP assignment and IP connectivity
Debug Information
- System diagnostics are enabled by default
- Serial output provides detailed operation status
- HTTP server runs on port 80 for additional configuration options
Customization Options
Server Configuration
Replace hardcoded IP with configurable parameters:
static config_string gTftpServerName{appdata,
"DNS_or_IPAddress",
"TFTP_SERVER"};
static config_IPADDR4 gTftpServerAddress(appdata,
"10.1.1.123",
"TFTP_SERVER");
Configuration Variable for IPADDR4 (IPv4) object types.
Definition config_obj.h:1493
String Configuration Variable.
Definition config_obj.h:1127
Buffer Size
Adjust bufferSize constant to handle larger file transfers as needed.
Timeout Values
Modify timeout parameters in function calls:
TICKS_PER_SECOND * 10: Overall operation timeout
TICKS_PER_SECOND * 5: Individual packet timeout
Development Notes
- Remove
EnableSystemDiagnostics() for production deployments
- Consider implementing error recovery mechanisms for production use
- The application demonstrates basic TFTP functionality suitable for embedded systems
- HTTP server provides additional configuration capabilities through web interface