ESP8266FtpServer for ESP8266. Access by FTP to SPIFFS or LittleFS files

ESP8266FtpServer echange fichier esp8266 spiffs
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on email
Share on whatsapp
drapeau france

The ESP8266FtpServer.h library developed by David Paiva (nailbuster on GitHub) allows you to add a small FTP server to an ESP8266 project. It can be used to retrieve data files or remotely update the HTML interface files, the data file of a data acquisition.

 

The SPIFFS file system for ESP8266 is used to store files in the memory area of the ESP8266 module. We can separate the code of the HTML interface (HTML file, CSS style sheet, javascript code) as well as data or parameter files. The fs.h library is a simplified implementation of the SPIFFS file system with C ++ Arduino code that does not offer any method to access files remotely using FTP.

Limitations of the SPIFFS File System

Before you begin, remember that the SPIFFS file system is very limited.

  • There is no tree management. Files are stored flat in the memory area
  • It is possible to use the / character in the file name. We can create a pseudo tree structure
  • The file name is limited to 31 useful characters including the file extension (4 characters)
  • Avoid using SPIFFS beyond 128MB of storage
  • Writing time is very variable

Add the ESP8266FtpServer.h library to an ESP8266 project

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

First of all, if you developed an HTML interface for an ESP8266 project, you will be able to update files without having to go through the Arduino IDE.

Second scenario, you use the ESP8266 to develop a stand-alone data acquisition system. You can take advantage of the SPIFFS file system to save measurements. Convenient to resume a recording in case of restart. This solution also eliminates the need to add an SD board reader.

Go to the project’s GitHub page here then download the project code

Ajouter la librairie ESP8266FtpServer à un projet ESP8266

Unzip the ZIP archive then move the ESP8266FtpServer.cpp and ESP8266FtpServer.h files to the root of the project.

Example of an FTP file server on ESP8266

Create a new sketch on the Arduino IDE and paste the following code.

Modify the following parameters:

  • WiFi username and password
  • Username and password of the FTP server
#include <ESP8266WiFi.h>
#include "ESP8266FtpServer.h"

const char* ssid = "enter_your_ssid";
const char* password = "enter_your_password";
const char* ftp_user = "esp8266";
const char* ftp_password = "esp8266";
//#define FTP_DEBUG true //enable debug on serial 

FtpServer ftpSrv;   
void setup()
{
  Serial.begin(112500);

  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print(" | IP address: ");
  Serial.println(WiFi.localIP());

  Serial.println(F("Inizializing FS..."));

  // Mount SPIFFS File system 
  if (SPIFFS.begin()) {
    Serial.println("SPIFFS opened!");
    // Then start FTP server when WiFi connection in On
    ftpSrv.begin(ftp_user, ftp_password);   
  }
}

void loop() {
  //make sure in loop you call handleFTP()!!
  ftpSrv.handleFTP();        
}

How Arduino C++ Code Works

As the library files are at the same level as the ino file, we declare the ESP8266FtpServer.h library between quotes to indicate to the compiler that we must use the local files.

#include "ESP8266FtpServer.h"

We then create the C++ object that will start the FTP server and manage external requests

FtpServer ftpSrv;

When starting the ESP8266, we start the FTP server using the begin() method in the setup(). The begin method of the FtpServer object takes two parameters which allow you to define the login credentials for the FTP server(user, password).

if (SPIFFS.begin()) {
   Serial.println("SPIFFS opened!");
   ftpSrv.begin("esp8266", "esp8266"); // username, password for ftp. Set ports in ESP8266FtpServer.h (default 21, 50009 for PASV)
}

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

void loop(void){
  ftpSrv.handleFTP();
}

Other parameters can be configured directly in the library

  • Define FTP_DEBUG uncomment 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.

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.

We save a lot of time in the development of HTML interfaces by avoiding having to re-upload all the project code to the ESP8266.

The dplasa fork for LittleFS files

Daniel Plasa (GitHub page) has made an adaptation fork of the library to make it compatible with the LittleFS file system.

Go to GitHub here and download the source code for the project

Fork du projet esp8266ftpserver pour système de fichier LittleFS pour ESP32 et ESP8266

Directly unzip the GitHub repository in the Documents -> Arduino -> Libraries folder

Relaunch the Arduino IDE

The LittleFSserver example allows remote access to the LittleFS memory area in FTP

Exemple FTP LittleFS pour ESP8266

Since this is a fork, the programming is similar to the original nailbuster project.

The library is not yet compatible with ESP32.

Updates

09/03/2020 New ftp server source code example

08/29/2020 Addition of the Daniel Plasa fork allowing access to the LittleFS file system in FTP

Click to rate this post!
[Total: 0 Average: 0]

Are you having a problem with this topic?

Maybe someone has already found the solution, visit the forum before asking your question
Ask your question

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on email
Share on whatsapp

Did you like this project ? Don't miss any more projects by subscribing to our weekly newsletter!

We will be happy to hear your thoughts

      Leave a Reply

      DIY Projects