ESP8266 (FTP server): file exchange with the SPIFFS file system, rapid development Web Server

The ESP8266 (and Arduino) SPIFFS file system can be used to store files from a Web server as well as data files (using the ESP8266 as a data acquisition system, for example). It is very easy to access the SPIFFS file system from the Arduino code via the FS.h library, but nothing is provided to access from another computer in FTP. In this tutorial, we will test the ESP8266FtpServer.h library developed by David Paiva (nailbuster on GitHub) which allows to add a small FTP server to the ESP8266, sufficient to deposit and retrieve files.

Add the ESP8266FtpServer.h library to an ESP8266 project

The library ESP8266FtpServer.h is still under development. It is an adaptation of the Arduino bookshop in Gallegojm. It can do us a lot of service in two situations.

First of all, if you have developed your own HTML interface for your ESP8266 project, you must download the entire SPIFFS system at each change. On a Wemos D1 Mini that has 4MB of Flash memory, it is necessary to download a file of 3MB. Even at 921600 baud, the operation lasts 2 minutes and 35 seconds. It may pass for a small interface, but for a large project, it is quickly problematic.

Second, you use the ESP8266 to develop a standalone data acquisition system. You can take advantage of the SPIFFS file system to record measurements. Convenient to resume recording when restarted. This solution also avoids having to add and manage an SD card reader.

To use the library in your project, it will be necessary to manually add the two files (.cpp and .h) because it is not available from the library manager. The easiest way is to download the repository from GitHub. Open your project and drag the two files.

Adding an FTP Server to a Project ESP8266

Now that the library is added to your project, declare it at the beginning of the code

Next, an object

In the setup() function, the user credentials (user, password) are configured.

Finally, the requests to connect to the server(handleFTP function) are monitored in the loop().

Other parameters can be configured directly in the library

  • Define FTP_DEBUG: de-comment to enable sending debug messages on the serial monitor (convenient for debugging)
  • FTP_CTRL_PORT: port of the FTP server. By default, this is the 21
  • FTP_TIME_OUT: time before automatic disconnection (I have a doubt on its functioning)

It’s finished, you can now access your files in FTP.

Accessing SPIFFS using Filezilla

In the current version, only the passive mode is supported. SFTP (Secure FTP) is not supported. If you do not know Filezilla, you can start by reading this tutorial.

Start FileZilla. The easiest way to connect to an ESP8266 in FTP and use the site manager. I encountered difficulties using the Quick Connect bar. Open the Site Manager from the File menu and configure the access as follows:

  • Host: IP address of the ESP8266
  • Port: 21 (or the one configured by the FTP_CTRL_PORT key)
  • Protocol: TFP – File Transfer Protocol
  • Encryption: Simple FTP connection (not secure)
  • Authentication type: Normal
  • Username and Password

 filezilla esp8266 ftp connexion spiffs

Start the connection by clicking Connect. The connection is now registered by FileZilla, it will no longer be necessary to redo it. Once the connection is established, you have access to all files in the Data directory (the Arduino project directory). As you can see, the tree structure is not yet very well managed. Unless you fix the library, you will have to abandon the organization of the files in dedicated directories (js, img, css …).

filezilla fichiers spiffs esp8266 wemos d1 mini

By activating the debug messages, here is what happens on the Arduino IDE serial monitor.

esp8266-ftp spiffs filezilla monitor serial ide arduino

So, I hope you will save a lot of time in developing your Web Server projects on ESP8266.

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

Tags:

DIY Projects