FTP server on esp8266 and esp32

Spread the love

When I develop a new solution, I’d like to divide the application into layers, and so I’d like to focus my attention on only one aspect at a time.

In detail, I separate the REST layer (written inside the microcontroller) and the Front-End (composed in Angular, React/Redux, or vanilla JS), so I’d like to upload a new web interface directly to the microcontroller via FTP.

FTP file transfer on esp8266 or esp32

For static information (Web pages, for example) that do not change frequently, esp8266 or esp32 have internal SPIFFS (SPI Flash File System). You can upload data via Arduino IDE as explained in the article “WeMos D1 mini (esp8266), integrated SPIFFS Filesystem” for esp8266 or “ESP32: integrated SPIFFS FileSystem” for esp32 or with LittleFS “WeMos D1 mini (esp8266), integrated LittleFS Filesystem” for esp8266 or “ESP32: integrated LittleFS FileSystem” for esp32 or “ESP32: integrated FFat (FAT/exFAT) FileSystem” but for fast operation and future support It usefully uses FTP.

I find a simple library that works quite well, and It’s not hungry for resources; you can find It here.

In time, this library becomes buggy and had deficient support, so I fix It, and now you can retrieve the library from here.

Library

The library is available directly from the Library Manager of Arduino IDE.

Or the source code from GitHub.

You can find my library here.

To download.

Click the DOWNLOADS button in the top right corner, and rename the uncompressed folder SimpleFTPServer.

Check that the SimpleFTPServer contains FtpServer.cpp, FtpServer.h, FtpServerKey.h e SimpleFTPServer.h .

Place the SimpleFTPServer library folder in your /libraries/ folder.

You may need to create the libraries subfolder if it’s your first library.

Restart the IDE.

Select FS on esp8266

You can also enable LittleFS for esp8266 by editing the line in the FtpServerKey.h file

	#define DEFAULT_STORAGE_TYPE_ESP8266 STORAGE_SPIFFS

in

	#define DEFAULT_STORAGE_TYPE_ESP8266 STORAGE_LITTLEFS

Usage

Here is an example for esp8266

/*
 *  WeMos D1 mini (esp8266)
 *  Start FTP server to upload data on SPIFFS
 *  by Mischianti Renzo <https://mischianti.org>
 *
 *  https://mischianti.org/wemos-d1-mini-esp8266-integrated-spiffs-filesistem-part-2/
 *
 */

#include "Arduino.h"

#include <ESP8266WiFi.h>
#include <SimpleFtpServer.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASS";


FtpServer ftpSrv;   //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial


void setup(void){
  Serial.begin(115200);
  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());

  /////FTP Setup, ensure SPIFFS is started before ftp;  /////////
  if (SPIFFS.begin()) {
//	  SPIFFS.format();
      Serial.println("SPIFFS opened!");
      ftpSrv.begin("esp8266","esp8266");    //username, password for ftp.  set ports in ESP8266FtpServer.h  (default 21, 50009 for PASV)
  }
}
void loop(void){
  ftpSrv.handleFTP();        //make sure in loop you call handleFTP()!!
}

Select FS on esp32

You can also enable LittleFS for esp32 by editing the line in the FtpServerKey.h file

	#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_SPIFFS

in

	#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_LITTLEFS

or this for FFAT

	#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_FFAT

Here the complete list of options.

#define STORAGE_SDFAT1 		1 	// Library SdFat version 1.4.x
#define STORAGE_SDFAT2 		2 	// Library SdFat version >= 2.0.2
#define STORAGE_SPIFM  		3 	// Libraries Adafruit_SPIFlash and SdFat-Adafruit-Fork
#define STORAGE_FATFS  		4 	// Library FatFs
#define STORAGE_SD 			5 	// Standard SD library (suitable for Arduino esp8266 and esp32
#define STORAGE_SPIFFS 		6 	// SPIFFS
#define STORAGE_LITTLEFS 	7 	// LITTLEFS
#define STORAGE_SEEED_SD 	8 	// Seeed_SD library
#define STORAGE_FFAT  		9 	// ESP32 FFAT
#define STORAGE_SD_MMC		10 	// SD_MMC library

Not all are compatible with our device.

Usage

Here for esp32

/*
 *  ESP32 Dev Kit (esp32)
 *  Start FTP server to upload data on SPIFFS
 *  by Mischianti Renzo <https://mischianti.org>
 *
 *  https://mischianti.org/wemos-d1-mini-esp8266-integrated-spiffs-filesistem-part-2/
 *
 */

#include <WiFi.h>
#include "SPIFFS.h"

#include <SimpleFtpServer.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASS";


FtpServer ftpSrv;   //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial


void setup(void){
  Serial.begin(115200);
  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());

  /////FTP Setup, ensure SPIFFS is started before ftp;  /////////
  if (SPIFFS.begin(true)) {
      Serial.println("SPIFFS opened!");
      ftpSrv.begin("esp8266","esp8266");    //username, password for ftp.  set ports in ESP8266FtpServer.h  (default 21, 50009 for PASV)
  }    
}
void loop(void){
  ftpSrv.handleFTP();        //make sure in loop you call handleFTP()!!  
}

This library support only passive mode and you must force only one connection at time.

I use FileZilla as a client, and you can download It here; It is pretty simple to use and configure.

Filezilla configuration for access esp8266, select plain FTP on Manage Site

First, you must go on Manage site --> New site and now set this parameter:

  • Select FTP as protocol;
  • Select Use plain FTP (insecure);
  • Set your login and password (you choose that in the sketch);
  • Than on Trasfer settings select Maximun number of connection equal 1;
  • Now connect to your device.
Filezilla configuration for access esp8266, select max num connections

Now, you can manage your SPIFFS with drag and drop.

Remember that SPIFFS does not manage folders, so all files must be flat.

Test

To check the upload, you can use the simple sketch used in the SPIFFS article linked up:

/*
 *  WeMos D1 mini (esp8266)
 *  SPIFFS get info, read dir and show all file uploaded
 *  add a data folder to use with esp8266 data uploader
 *  by Mischianti Renzo <https://mischianti.org>
 *
 *  https://mischianti.org/wemos-d1-mini-esp8266-integrated-spiffs-filesistem-part-2/
 *
 */

#include "Arduino.h"
#include "FS.h"

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

	delay(500);

	Serial.println(F("Inizializing FS..."));
	if (SPIFFS.begin()){
		Serial.println(F("done."));
	}else{
		Serial.println(F("fail."));
	}

	// To format all space in SPIFFS
	// SPIFFS.format()

	// Get all information of your SPIFFS
	FSInfo fs_info;
	SPIFFS.info(fs_info);

	Serial.println("File sistem info.");

	Serial.print("Total space:      ");
	Serial.print(fs_info.totalBytes);
	Serial.println("byte");

	Serial.print("Total space used: ");
	Serial.print(fs_info.usedBytes);
	Serial.println("byte");

	Serial.print("Block size:       ");
	Serial.print(fs_info.blockSize);
	Serial.println("byte");

	Serial.print("Page size:        ");
	Serial.print(fs_info.totalBytes);
	Serial.println("byte");

	Serial.print("Max open files:   ");
	Serial.println(fs_info.maxOpenFiles);

	Serial.print("Max path length:  ");
	Serial.println(fs_info.maxPathLength);

	Serial.println();

	// Open dir folder
	Dir dir = SPIFFS.openDir("/");
	// Cycle all the content
	while (dir.next()) {
		// get filename
	    Serial.print(dir.fileName());
        Serial.print(" - ");
        // If element have a size display It else write 0
	    if(dir.fileSize()) {
	        File f = dir.openFile("r");
	        Serial.println(f.size());
	        f.close();
	    }else{
	    	Serial.println("0");
	    }
	}
}

void loop()
{

}

Test with callback

An interesting feature I added recently was the callback on some action

/*
 * FtpServer esp8266 and esp32 with SPIFFS
 *
 * AUTHOR:  Renzo Mischianti
 *
 * https://mischianti.org/ftp-server-on-esp8266-and-esp32
 *
 */

#ifdef ESP8266
#include <ESP8266WiFi.h>
#elif defined ESP32
#include <WiFi.h>
#include "SPIFFS.h"
#endif

#include <SimpleFTPServer.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASS";


FtpServer ftpSrv;   //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial

void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
  switch (ftpOperation) {
    case FTP_CONNECT:
      Serial.println(F("FTP: Connected!"));
      break;
    case FTP_DISCONNECT:
      Serial.println(F("FTP: Disconnected!"));
      break;
    case FTP_FREE_SPACE_CHANGE:
      Serial.printf("FTP: Free space change, free %u of %u!\n", freeSpace, totalSpace);
      break;
    default:
      break;
  }
};
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
  switch (ftpOperation) {
    case FTP_UPLOAD_START:
      Serial.println(F("FTP: Upload start!"));
      break;
    case FTP_UPLOAD:
      Serial.printf("FTP: Upload of file %s byte %u\n", name, transferredSize);
      break;
    case FTP_TRANSFER_STOP:
      Serial.println(F("FTP: Finish transfer!"));
      break;
    case FTP_TRANSFER_ERROR:
      Serial.println(F("FTP: Transfer error!"));
      break;
    default:
      break;
  }

  /* FTP_UPLOAD_START = 0,
   * FTP_UPLOAD = 1,
   *
   * FTP_DOWNLOAD_START = 2,
   * FTP_DOWNLOAD = 3,
   *
   * FTP_TRANSFER_STOP = 4,
   * FTP_DOWNLOAD_STOP = 4,
   * FTP_UPLOAD_STOP = 4,
   *
   * FTP_TRANSFER_ERROR = 5,
   * FTP_DOWNLOAD_ERROR = 5,
   * FTP_UPLOAD_ERROR = 5
   */
};

void setup(void){
  Serial.begin(115200);
  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());


  /////FTP Setup, ensure SPIFFS is started before ftp;  /////////
  
  /////FTP Setup, ensure SPIFFS is started before ftp;  /////////
#ifdef ESP32       //esp32 we send true to format spiffs if cannot mount
  if (SPIFFS.begin(true)) {
#elif defined ESP8266
  if (SPIFFS.begin()) {
#endif
      ftpSrv.setCallback(_callback);
      ftpSrv.setTransferCallback(_transferCallback);

      Serial.println("SPIFFS opened!");
      ftpSrv.begin("esp8266","esp8266");    //username, password for ftp.   (default 21, 50009 for PASV)
  }    
}
void loop(void){
  ftpSrv.handleFTP();        //make sure in loop you call handleFTP()!!  
 // server.handleClient();   //example if running a webserver you still need to call .handleClient();
 
}

Here is a simple upload of a README.md file.

.......
Connected to reef-casa-sopra 
IP address: 192.168.1.127
LittleFS opened!
FTP: Connected!
FTP: Upload start!
FTP: Upload of file README.md byte 1072
FTP: Upload of file README.md byte 3120
FTP: Upload of file README.md byte 3559
FTP: Finish transfer!
FTP: Free space change, free 1019904 of 1036288!

Thanks.

  1. SimpleFTPServer library: esp32 and esp8266 how to
  2. SimpleFTPServer library: WioTerminal how to
  3. FTP server on STM32 with w5500, enc28j60, SD Card, and SPI Flash

Spread the love

57 Responses

  1. Rodrigo says:

    Good afternoon
    I’ve been looking for and testing some examples of FTPServer with esp32 and I found yours (great by the way) works perfectly as WIFIClient …
    Would it be possible to use WIFI as WIFI_AP?

  2. Kemran says:

    Hi, how can i turn wifi station mode to the wifi acces point mode? İ want to connect to the esp8266 and then upload file.

  3. Cameron Leckie says:

    Hello, thanks for this library. I am using a Sparkfun ESP32 Thing microprocessor with an SD card attached for data logging purposes and connected to a WiFi network. I am aiming to be able to download files from the SD card via ftp (I am using Filezilla). The example script SimpleFTPserver works and I can successfully download the documents stored in SPIFFS via Filezilla.

    Based on the commentary in the article I thought that I might be able to modify FtpServerKey.h as detailed below such that I can access/point the ftp server to the SD card rather than SPIFFS:

    Replace: #define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_SPIFFS with #define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_SD.

    However I get a series of compilation errors when I attempt this. Examples are:

    C:\Users\lecko\Documents\Arduino\libraries\SimpleFTPServer-master\FtpServer.cpp: In member function 'bool FtpServer::processCommand()':
    C:\Users\lecko\Documents\Arduino\libraries\SimpleFTPServer-master\FtpServer.cpp:581:31: error: 'FTP_FILE_READ' was not declared in this scope
               if( openFile( path, FTP_FILE_READ ))
    

    I am new to this and quickly getting out of my depth.

    I was wondering whether there is a simple fix to allow the ftp server to point to the SD card rather than SPIFFS?

    Many thanks

    • Hi Cameron,
      sorry, i forgot to push some files. I’m going to do that at lunch.

      You must change these lines in FtpServerKey.h

      #ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32
      	#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32 	NETWORK_ESP32
      	#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_SPIFFS
      #endif
      

      in

      #ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32
      	#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32 	NETWORK_ESP32
      	#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_SD
      #endif
      

      Bye Renzo

    • I push the change.
      Sorry again Bye Renzo

  4. Jun Chun says:

    I tried to run on ESP32, but filezilla could not coneect to the board. It kept trying to connect and timed out.

  5. moniteur says:

    hello, very well your article it allowed me to advance on my project.
    I have a problem with AndFTP, (android) it does not manage to display the list of files (on filezilla win10 no problem)
    can you help me ? thank you

  6. moniteur says:

    hello, hooo great from you that will help me a lot. Thank you a lot.
    I’m waiting for your feedback!

  7. moniteur says:

    hello thanks for your work, i loaded from github, i replaced the FtpServer.cpp file.
    the application connects well, starts loading, then nothing, a message is displayed real time out.
    on the app the information I have are: site free -211 end -PASV.
    j on the console the last line is: Command is: PASV
    Connection management set to passive
    Listening at xxx.xxx.xxx.xxx:50009
    thank you for your help

  8. christian says:

    Hi Renzo,
    thanks for this great effort! On my ESP32 I was able to reproduce your ftp-server example based on SPIFFS. For certain reasons, I need to switch to an SD card as file destination.

    To ensure functionality of the SD card, I followed your instructions on How to use SD card with esp32 – SD card works perfectly. Then I followed you hint in the earlier post here and made the change in FtpServerKey.h (“STORAGE_SPIFFS” –> “STORAGE_SD”; to verify that I modified the file in the right folder I additionally changed the welcome message in FtpServer.cpp located in the same directory).

    Then I took your example sketch from FTPServer_Arduino_esp32_SD and changed ssid & password to my needs. In order to get the SD card up and running with the wiring from the previous example, I exchanged the line “SPI.begin(14, 2, 15, 13); //SCK, MISO, MOSI, SS” into “SPI.begin(18, 19, 23, 5); //SCK, MISO, MOSI, SS” and line “if (SD.begin(13, SPI)) {” into “if (SD.begin(5, SPI)) {“. Sketch compiles nicely, SD card is recognized, ftp server can be reached from outside (bash command line ftp client on my Ubuntu laptop, that I used successfully before with the SPIFFS/FTP example).

    But: the remote directory appears to be empty (“dir”); file upload with “put” appears to work, but the target directory stays empty. Do you have any ideas? Or could you even make the destination (SPIFFS / SD) easier configurable?
    Thanks, Christian

    • Hi Christian,
      I retry now the SD sketch with STORAGE_SD configuration and all works correctly.
      Open a topic in the relative forum http://mischianti.org/forums/forum/mischiantis-libraries/simple-ftp-server/ and we are going to check better.
      Bye Renzo

      • christian says:

        Hi Renzo,
        thanks for your quick response.

        This prompted me to try it out again with “fresh” hardware: I used a new ESP32 with a new SD shield and a new SD card and – guess what – it worked!

        With some re-wiring experiments I was able to trace it down to the first ESP32 I had originally used to be the source of problem.
        I can come up with 2 ideas:
        a) the first ESP32 simply has a hardware problem, but I have my doubts as the rest works, it is wired with a GPS sensor (serial2) and a BME280 (I2C), both writing data to an SD card or
        b) SPIFFS was initialized on the first ESP32 but not on the second

        Did you ever experience problems in case you switch from an SPIFFS enabled ESP32 FTP server to and SD card based?
        Anyway, thanks a lot for your great work. This and also your other projects are a source of inspiration 🙂
        Cheers, Christian

        • Hi Christian,
          I used an ESP32 to test SPIFFS and SD FTP server, and I didn’t have problems.
          But after a lot of different test (and issue) sometime I resolved with true parameter on begin (format on fail):

          SPIFFS.begin(true); // true to format on fail
          

          I’m pleased if you want to share your work if you want. In case, contact me on share_your_ideas@mischianti.org.

          Bye Renzo

  9. josemacc says:

    Hi Renzo,
    I’ve noticed that in Arduino, when you work with LittleFS, the library name and everything else is with “LITTLEFS” I repaced all the “LittleFS” for “LITTLEFS” and everyting works fine.
    Thanks for the Tutorial!

    • Hi josemacc,
      I never used LittleFS with Arduino, I tested It only for esp8266 and esp32.

      #elif(STORAGE_TYPE == STORAGE_LITTLEFS)
      	#if ESP8266
      		#include "LittleFS.h"
      		#define STORAGE_MANAGER LittleFS
      		#define FTP_FILE File
      		#define FTP_DIR Dir
      
      		#define FTP_FILE_READ "r"
      		#define FTP_FILE_READ_ONLY "r"
      		#define FTP_FILE_READ_WRITE "w+"
      		#define FTP_FILE_WRITE_APPEND "a+"
      		#define FTP_FILE_WRITE_CREATE "w+"
      	#else
      #if ESP_ARDUINO_VERSION_MAJOR >= 2
      		#include "FS.h"
      		#include "LittleFS.h"
      		#define STORAGE_MANAGER LittleFS
      #else
      		#include "LITTLEFS.h"
      		#define STORAGE_MANAGER LITTLEFS
      #endif
      
      

      Probably is better if I invert the if with the control of ESP framework version.
      Thanks Renzo

  10. Ayush Dutta says:

    how can i run a REST API Client alongside this

  11. Pawel says:

    Renzo, thank You for jour job. I suggest changing one line in FtpServer.h if we want to use MMC.
    […]
    #elif(STORAGE_TYPE == STORAGE_SD_MMC)
    #include
    #include

    #define STORAGE_MANAGER SD_MMC //here was SD
    […]

  12. alexx says:
    #ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266
    	#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266 	NETWORK_ESP8266
    	#define DEFAULT_STORAGE_TYPE_ESP8266 				STORAGE_SD
    #endif
    

    Help.. i get erros, how do i use SD card with sp8266 ?

  13. alexx says:
    #elif(STORAGE_TYPE == STORAGE_SD)
    	#include 
    	#include 
    
    	#define STORAGE_MANAGER SD
      	#define FTP_FILE File
      	#define FTP_DIR File
    
    	#define FTP_FILE_READ FILE_READ
    	#define FTP_FILE_READ_ONLY FILE_READ
    	 #define FTP_FILE_WRITE_APPEND FILE_WRITE
    	#define FTP_FILE_WRITE_CREATE FILE_WRITE
    	#define FTP_FILE_READ_WRITE FILE_WRITE
    		#define FILENAME_LENGTH 32
    

    I made these changes at FtpServer.h at line 324 and now it is working fine with SD on esp8266. so never mind my previews post. i guess?

    PS. i have not idea what i did, i just mix and matched in the code, i guess maximum file length should be 255 ???? and FILENAME_LENGTH 32 stands for littleFs or something else ? anyway.. for my use case it works just fine with the changes i did, i am not going to touch it since it works now.. until the lovely developer pushes an update.

  14. Albi says:

    Hi Renzo,
    thanks for this library. On an ESP8266 I was able to reproduce your ftp-server example “esp8266_esp32_LittleFS.ino” based on LITTLEFS. For my project, I have added a W5500 to the ESP8266 for Ethernet connection. So I have changed line 54 of FtpServerKey.h to “#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266 NETWORK_W5100”. But if I compile my project with this change I get the following compiler errors:

    C:\Users\albid\Documents\Arduino\libraries\SimpleFTPServer\FtpServer.cpp: In member function 'void FtpServer::begin(const char*, const char*, const char*)':
    C:\Users\albid\Documents\Arduino\libraries\SimpleFTPServer\FtpServer.cpp:74:13: error: 'class EthernetServer' has no member named 'setNoDelay'
       ftpServer.setNoDelay( true );
                 ^
    C:\Users\albid\Documents\Arduino\libraries\SimpleFTPServer\FtpServer.cpp:94:14: error: 'class EthernetServer' has no member named 'setNoDelay'
       dataServer.setNoDelay( true );
                  ^
    C:\Users\albid\Documents\Arduino\libraries\SimpleFTPServer\FtpServer.cpp: In member function 'uint8_t FtpServer::handleFTP()':
    C:\Users\albid\Documents\Arduino\libraries\SimpleFTPServer\FtpServer.cpp:203:19: error: 'class EthernetServer' has no member named 'hasClient'
         if( ftpServer.hasClient())
                       ^
    C:\Users\albid\Documents\Arduino\libraries\SimpleFTPServer\FtpServer.cpp: In member function 'int FtpServer::dataConnect(bool)':
    C:\Users\albid\Documents\Arduino\libraries\SimpleFTPServer\FtpServer.cpp:999:19: error: 'class EthernetServer' has no member named 'hasClient'
        if( dataServer.hasClient())
                       ^
    

    What I’m doing wrong? Thanks for your response.
    Albrecht

  15. Albi says:

    I have already posted an answer, but now I can’t see it. Ethernet library is Ethernet.h by Paul Stoffregen Version 2.0.0.
    Regards
    Albrecht

  16. Soil_Maker_FR says:

    Hi Renzo, thanks for sharing this usefull library.
    I want to use it for a datalogger, storing a csv on SPIFFS in a ESP32 firebeetle (16M flash), and transfer it easily to my laptop. I manage to do it with arduino exemple WebServer, but FTP server, and the script, looks much lighter and better for my purpose.
    I can run the script, connect to wifi (phone and office), open SPIFFS, connect to http://FTP... but on FileZilla I can’t see my files (I’m sure there is one, i added a few lines to create one and list the files on the terminal at the end ot stup() ).
    When i try to transfer from FileZilla to ESP32 I also get an error. see below

    rst:0x1 (POWERON_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff0018,len:4
    load:0x3fff001c,len:1044
    load:0x40078000,len:8896
    load:0x40080400,len:5816
    entry 0x400806ac
    
    ....
    Connected to SFR_EFA0
    IP address: 192.168.1.88
    SPIFFS opened!
    Writing file: /test2.txt
    - file written
    Listing directory: /
      FILE: /test2.txt	SIZE: 5
    FTP: Connected!
    FTP: Upload start!
    Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
    Core 1 register dump:
    PC      : 0x400014fd  PS      : 0x00060830  A0      : 0x8010bbb8  A1      : 0x3ffb1a60  
    A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00  
    A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3ffb1e00  
    A10     : 0x00000001  A11     : 0x00000000  A12     : 0x3ffcde40  A13     : 0x00000000  
    A14     : 0x00000000  A15     : 0x00000007  SAR     : 0x00000019  EXCCAUSE: 0x0000001c  
    EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  
    
    Backtrace: 0x400014fd:0x3ffb1a60 0x4010bbb5:0x3ffb1a70 0x4011312e:0x3ffb1d80 0x4011316a:0x3ffb1e10 0x400d5ed2:0x3ffb1e50 0x400d127a:0x3ffb1ef0 0x400d564a:0x3ffb1f10 0x400d58f9:0x3ffb1f40 0x400d129a:0x3ffb1f90 0x400d6871:0x3ffb1fb0 0x40088ba1:0x3ffb1fd0
    
    Rebooting...
    

    I followed the setup for FIleZilla, tried to play with spiffs partition, googled everything i could but I’m now stuck on it since yesterday.

    Do you have any clue on have to solve this ?

    Thanks

    • Hi Soil_Maker_FR,
      mmm.. I need more information, please open a topic and post your code.
      Bye Renzo

      • Soil_Maker_FR says:

        Thanks for repying, i will open a topic on GitHub and report all this.

        I thought the problem could come from SPIFFS because I had this error message when trying to upload :

        [ 20478][E][vfs_api.cpp:24] open(): File system is not mounted
        [ 20540][E][vfs_api.cpp:24] open(): File system is not mounted
        [ 20540][E][vfs_api.cpp:204] mkdir(): File system is not mounted
        [ 20610][E][vfs_api.cpp:24] open(): File system is not mounted
        [ 20823][E][vfs_api.cpp:24] open(): File system is not mounted

        So i tried with LitlleFS… but nothing changed.

        I will also try with an SD card and another Firebeetle Board (unfortunatly i have not other ESP32 board …). But my project will need to use ESP32 flash memory to save data… that was one of the reason to move from ATmega and SAMD21 to ESP32. By the way, this is my first project so maybe i miss something trivial with ESP32…

        Hope we can fix this ! I have multiple project in mind with ESP32 to monitor soils and ecosystems… but need a simple way to access data store in his flash memory !

  17. Albi says:

    Hi Renzo,
    thanks for the last weeks fix. With version 2.1.6 I can compile my project and the code is running. FileZilla connects to the server but the user login fails. Here the message log from FileZilla:
    14:05:23 Trace: CControlSocket::SendNextCommand()
    14:05:23 Trace: CFtpLogonOpData::Send() in state 0
    14:05:23 Status: Connecting to 192.168.178.70:21…
    14:05:23 Status: Connection established, waiting for welcome message…
    14:05:23 Trace: CFtpControlSocket::OnReceive()
    14:05:23 Response: 220—Welcome to Simply FTP server —
    14:05:23 Response: 220— By Renzo Mischianti —
    14:05:23 Trace: CFtpControlSocket::OnReceive()
    14:05:23 Response: 220 — Version 2.1.6 (2023-02-02) —
    14:05:23 Trace: CFtpLogonOpData::ParseResponse() in state 1
    14:05:23 Trace: CControlSocket::SendNextCommand()
    14:05:23 Trace: CFtpLogonOpData::Send() in state 5
    14:05:23 Status: Plain FTP is insecure. Please switch to FTP over TLS.
    14:05:23 Trace: CFtpControlSocket::SetAsyncRequestReply
    14:05:23 Trace: CControlSocket::SendNextCommand()
    14:05:23 Trace: CFtpLogonOpData::Send() in state 6
    14:05:23 Command: USER ftp
    14:05:30 Trace: CFtpControlSocket::OnReceive()
    14:05:30 Response: 331 Ok. Password required
    14:05:30 Trace: CFtpLogonOpData::ParseResponse() in state 6
    14:05:30 Trace: CControlSocket::SendNextCommand()
    14:05:30 Trace: CFtpLogonOpData::Send() in state 6
    14:05:30 Command: PASS ***
    14:05:33 Trace: CFtpControlSocket::OnReceive()
    14:05:33 Response: 530 Timeout
    14:05:33 Trace: CFtpLogonOpData::ParseResponse() in state 6
    14:05:33 Trace: CRealControlSocket::DoClose(1094)
    14:05:33 Trace: CControlSocket::DoClose(1094)
    14:05:33 Trace: CFtpControlSocket::ResetOperation(1094)
    14:05:33 Trace: CControlSocket::ResetOperation(1094)
    14:05:33 Trace: CFtpLogonOpData::Reset(1094) in state 6
    14:05:33 Error: Critical error: Could not connect to server
    14:05:33 Trace: CFileZillaEnginePrivate::ResetOperation(1094)
    The USER and PASS command do last very long and PASS command ends with error.
    I have double checked the behavior with WLAN, this is ok and works well.
    Thanks for your help.

    Bye Albi

  18. Fikry says:

    Hi Renzo….
    I have try it using ESP32 with SD Card. When connect it with Filezilla, the FTP Server have been successfully directory listing, but when transfer the file from local PC to FTP Server is failed with message error “Transfer connection interrupted: ECONNABORTED – Connection aborted” & “File transfer failed”. So can you assist me to solve it ? Thank you

    For your information, I have changed #define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_SPIFFS with #define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_SD in FtpServerKey.h file

  19. Norbert Temesi says:

    Dear Renzo,

    Is there a fuction in this library that I can use for detecting a connection?
    Now my program is waiting for 2 minutes for an incoming connection, if there is one then I have the remaining time within the 2 minutes timeframe then the code shuts down the connection and proceeds to the next phase.
    I need a solution for detecting a connection which “catches” the call then the time limit can be erased and finally the user’s disconnection pushes forward the code and not running out of the timeframe.

    Thanks for your help!
    Norbert

    • Hi Norbert,
      you can add a callback like so

        ftpSrv.setCallback(_callback);
      

      and intercept some type of events

      void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
        switch (ftpOperation) {
          case FTP_CONNECT:
            Serial.println(F("FTP: Connected!"));
            break;
          case FTP_DISCONNECT:
            Serial.println(F("FTP: Disconnected!"));
            break;
          case FTP_FREE_SPACE_CHANGE:
            Serial.printf("FTP: Free space change, free %u of %u!\n", freeSpace, totalSpace);
            break;
          default:
            break;
        }
      };
      
      

      Bye Renzo

  20. dams says:

    Hi Renzo,

    Is it exist a way to configure the type of file system to be use without modify the FtpServerKey.h file anytime ? I use the ftpserver in various projects with SD_card or SPIFFS. It is boring to change anytime the #define in the library file each time I switch from a project using SPIFFS to an other using a SD card.

    I tried to set the #define at the top of my sketch but it continue to use the value defined in the FtpServerKey.h file.
    If i place in comment the #define in the FtpServerKey.h file, the compilation fail as the compiler not found the definition in the top of sketch.

    Have you an idea ?

    Thanks for your help !
    Cheers

  21. Uli K says:

    Hi Renzo,
    thanks for the great library, but I have two Problems with esp8266:
    1. transferring a file from SD to PC results in an empty file on the PC (flash to PC works well)
    2. can I switch the up-/downloads from SD/PC to flash/PC without changing the FtpServerKey.h?

    • Hi Uli,
      for the first problem, try to check the FTP client setting as described in the article,
      for the second point, no, it isn’t possible; the server points to only one FS at a time.
      Bye Renzo

Leave a Reply

Your email address will not be published. Required fields are marked *