NetBurner 3.5.6
PDF Version
FTP Client

FTP Client Example

A NetBurner embedded FTP client application that demonstrates basic FTP operations including connecting to a server, directory navigation, file listing, file creation, and file retrieval.

Note
For FTP and SFTP using the EFFS file systesms, refer to examples in the \nburn\examples\EFFS folder

Overview

This application connects to an FTP server and performs the following operations:

  1. Establishes an FTP connection to a specified server
  2. Changes to a remote directory called "test1"
  3. Retrieves and displays the directory listing
  4. Creates a sample file named "WriteTest.txt" with test content
  5. Reads back the created file and displays its contents

Features

  • FTP server connection with authentication
  • Directory navigation and listing
  • File upload (creation) capability
  • File download and content display
  • Error handling and command result validation
  • Timeout handling for network operations

Hardware Requirements

  • NetBurner embedded device with network connectivity
  • Active network connection

Software Requirements

Setup Requirements

Before running this application, ensure the following prerequisites are met:

  1. FTP Server Access: You need access to a functioning FTP server
  2. Authentication: Valid username and password for the FTP server
  3. Directory Structure: A directory named "test1" must exist on the FTP server
  4. Permissions: Write permissions must be granted to the "test1" directory
  5. Configuration: Update the configuration defines in main.cpp (see Configuration section)

Configuration

Before compiling and running the application, modify the following defines in main.cpp to match your FTP server setup:

#define SERVER_IP_ADDR "10.1.1.193" // Replace with your FTP server IP
#define FTP_PORT 21 // Standard FTP port (usually 21)
#define USER "username" // Replace with your FTP username
#define PASS "password" // Replace with your FTP password
#define WRITE_TEST_FILE "WriteTest.txt" // Test file name

Application Flow

  1. Initialization: The application initializes the NetBurner system and waits for an active network connection
  2. FTP Connection: Establishes a connection to the FTP server using the configured credentials
  3. Directory Change: Changes to the "test1" directory on the remote server
  4. Directory Listing: Retrieves and displays the contents of the "test1" directory
  5. File Creation: Creates a new file "WriteTest.txt" with sample content:
    • "This is a test file"
    • "This is line 2 of the test file"
    • "Last Line"
  6. File Retrieval: Downloads and displays the contents of the newly created file
  7. Cleanup: Closes the FTP session and enters an infinite loop

Key Functions

ShowFileContents(int fdr)

Reads data from a file descriptor and displays it to stdout (debug serial port). Handles the data stream in 255-byte chunks with a 20-second timeout.

UserMain(void *pd)

The main application function that orchestrates all FTP operations. Includes comprehensive error handling and status reporting.

Error Handling

The application includes robust error handling for:

  • FTP session initialization failures
  • Directory change failures
  • File listing failures
  • File creation failures
  • File retrieval failures
  • Command result validation (expects FTP code 226 for successful operations)

Output

The application provides detailed console output including:

  • Connection status messages
  • Directory listing contents
  • File creation confirmation
  • File content display
  • Error messages with specific error codes

Timeout Configuration

All FTP operations use a 5-second timeout (5 * TICKS_PER_SECOND) to prevent hanging on network issues.

Production Notes

  • The application enables system diagnostics which should be removed for production code
  • Consider implementing more sophisticated error recovery mechanisms for production use
  • Hardcoded credentials should be replaced with secure configuration methods in production

Compilation

Compile this application using the NetBurner development tools with the standard NetBurner RTOS libraries linked.

Troubleshooting

Common issues and solutions:

  1. Connection Failures: Verify IP address, port, username, and password
  2. Directory Not Found: Ensure "test1" directory exists on the FTP server
  3. Permission Denied: Verify write permissions to the target directory
  4. Network Issues: Check network connectivity and firewall settings
  5. Timeout Errors: Consider increasing timeout values for slow network connections