This ESP32 project is a FTP client that can download files from a remote server and store them in flash memory.
- ESP32 development board
- ESP-IDF v5.4.1 or later
- Clone the repository:
git clone https://github.com/fabiooo4/esp32_ftp_client.git cd esp32_ftp_client
- Build the project:
idf.py build
- Flash the project to the ESP32 (flash also builds the project):
idf.py flash
- Monitor the ESP32:
idf.py monitor
The project is configured using the ESP-IDF menuconfig tool. To open the configuration menu, run the following command:
idf.py menuconfig
All the possible FTP Client configurations can be found in the menuconfig
under FTP Client configuration
.
In Wifi station configuration
set the SSID and password of the wifi network
you want to connect to. You can also change other parameters.
In FTP Server configuration
set the IP and Port of the FTP server
you want to connect to.
If the FTP server requires authentication, set the username and password
in FTP Server authentication
menu.
In Serial Flasher Config/Flash Size
set the amount of flash memory available
on your model of microcontroller.
In Partition Table/Partition Table
set the option "Custom Partition Table CSV".
This option expects a "partitions.csv" file that defines the custom partitions.
To add another storage partition add the configuration line to partitions.csv
,
for example:
# Name, Type, SubType, Offset, Size, Flags
storage, data, spiffs, 0x110000, 0x100000,
Spiffs stands for "SPI Flash File System" wich is a lightweight filesystem that is designed to work with flash memory. The last two numbers are the start address and the size of the partition.
To add default files to the ESP32 filesystem from the project root folder, add
the following line to main/CMakeLists.txt
:
spiffs_create_partition_image(<partition> <base_dir> [FLASH_IN_PROJECT] [DEPENDS dep dep dep...])
With this command the build configuration is automatically passed to the tool, ensuring that the generated image is valid for that build.
Optionally, you can opt to have the image automatically flashed together with
the app binaries, partition tables, etc. on idf.py flash
by specifying
FLASH_IN_PROJECT
. For example:
spiffs_create_partition_image(my_spiffs_partition my_folder FLASH_IN_PROJECT)
In Component config/ESP System Settings/Main Task Stack Size
has been set to
5120
bytes to prevent stack overflow errors due to large data buffers.
This code is tested with the following steps:
- Connect to the FTP server.
- Login to the FTP server.
- List the remote directory.
- Create a directory on the FTP server.
- Upload a file to the FTP server.
- Change the current directory to the created directory.
- Print the current working directory.
- List the remote directory again.
- Download the file from the FTP server.
- Delete the file from the FTP server.
- Go to the parent directory.
- Print the current working directory.
- Remove the created directory from the FTP server.
- Rename a file on the FTP server.
- Access a file on the FTP server.
- Edit the file on the FTP server.
- Close the file on the FTP server.
- List the remote directory again.
- Get the file from the FTP server and check if its contents match the edited content.
- Remove the file from the FTP server.
- Close the FTP connection.
At the end of the program, the FTP connection is closed and no files or directories are left on the server.