From 010010f8a1d066a68533e32575370abae16769ae Mon Sep 17 00:00:00 2001 From: nailbuster Date: Wed, 18 Oct 2017 12:59:52 -0400 Subject: ESP32 Support Changes A few fixes and support for ESP32 --- ESP8266FtpServer.cpp | 38 +++++++++++------------ ESP8266FtpServer.h | 4 +-- examples/FTPServerSample/FTPServerSample.ino | 46 ++++++++-------------------- library.json | 2 +- library.properties | 2 +- 5 files changed, 36 insertions(+), 56 deletions(-) diff --git a/ESP8266FtpServer.cpp b/ESP8266FtpServer.cpp index f981682..7d25e9a 100644 --- a/ESP8266FtpServer.cpp +++ b/ESP8266FtpServer.cpp @@ -21,10 +21,8 @@ #include "ESP8266FtpServer.h" #ifdef ESP8266 #include -#include #elif defined ESP32 #include -#include #include "SPIFFS.h" #endif #include @@ -155,7 +153,7 @@ void FtpServer::clientConnected() #ifdef FTP_DEBUG Serial.println("Client connected!"); #endif - client.println( "220--- Welcome to FTP for ESP8266 ---"); + client.println( "220--- Welcome to FTP for ESP8266/ESP32 ---"); client.println( "220--- By David Paiva ---"); client.println( "220 -- Version "+ String(FTP_SERVER_VERSION) +" --"); iCL = 0; @@ -274,7 +272,7 @@ boolean FtpServer::processCommand() if (data.connected()) data.stop(); //dataServer.begin(); //dataIp = Ethernet.localIP(); - dataIp = WiFi.localIP(); + dataIp = client.localIP(); dataPort = FTP_DATA_PORT_PASV; //data.connect( dataIp, dataPort ); //data = dataServer.available(); @@ -385,9 +383,9 @@ boolean FtpServer::processCommand() uint16_t nm = 0; #ifdef ESP8266 Dir dir=SPIFFS.openDir(cwdName); - if( !SPIFFS.exists(cwdName)) - client.println( "550 Can't open directory " + String(cwdName) ); - else + // if( !SPIFFS.exists(cwdName)) + // client.println( "550 Can't open directory " + String(cwdName) ); + // else { while( dir.next()) { @@ -518,9 +516,9 @@ boolean FtpServer::processCommand() uint16_t nm = 0; #ifdef ESP8266 Dir dir=SPIFFS.openDir(cwdName); - if( !SPIFFS.exists( cwdName )) - client.println( "550 Can't open directory " + String(parameters)); - else + // if( !SPIFFS.exists( cwdName )) + // client.println( "550 Can't open directory " + String(parameters)); + // else { while( dir.next()) { @@ -768,16 +766,18 @@ boolean FtpServer::dataConnect() boolean FtpServer::doRetrieve() { - //int16_t nb = file.readBytes((uint8_t*) buf, FTP_BUF_SIZE ); +if (data.connected()) +{ int16_t nb = file.readBytes(buf, FTP_BUF_SIZE); - if( nb > 0 ) - { - data.write((uint8_t*) buf, nb ); - bytesTransfered += nb; - return true; - } - closeTransfer(); - return false; + if (nb > 0) + { + data.write((uint8_t*)buf, nb); + bytesTransfered += nb; + return true; + } +} +closeTransfer(); +return false; } boolean FtpServer::doStore() diff --git a/ESP8266FtpServer.h b/ESP8266FtpServer.h index 877ad24..00a8057 100644 --- a/ESP8266FtpServer.h +++ b/ESP8266FtpServer.h @@ -35,7 +35,7 @@ #include #include -#define FTP_SERVER_VERSION "FTP-2016-01-14" +#define FTP_SERVER_VERSION "FTP-2017-10-18" #define FTP_CTRL_PORT 21 // Command port on wich server is listening #define FTP_DATA_PORT_PASV 50009 // Data port in passive mode @@ -44,7 +44,7 @@ #define FTP_CMD_SIZE 255 + 8 // max size of a command #define FTP_CWD_SIZE 255 + 8 // max size of a directory name #define FTP_FIL_SIZE 255 // max size of a file name -// #define FTP_BUF_SIZE 1024 //512 // size of file buffer for read/write +//#define FTP_BUF_SIZE 1024 //512 // size of file buffer for read/write #define FTP_BUF_SIZE 2*1460 //512 // size of file buffer for read/write class FtpServer diff --git a/examples/FTPServerSample/FTPServerSample.ino b/examples/FTPServerSample/FTPServerSample.ino index 06223df..b8fa5f6 100644 --- a/examples/FTPServerSample/FTPServerSample.ino +++ b/examples/FTPServerSample/FTPServerSample.ino @@ -1,35 +1,18 @@ +#ifdef ESP8266 #include -#include -#include +#elif defined ESP32 +#include +#include "SPIFFS.h" +#endif + #include const char* ssid = "YOUR_SSID"; const char* password = "YOUR_PASS"; -ESP8266WebServer server(80); -FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial - - -void handleRoot() { - server.send(200, "text/plain", "hello from esp8266!"); - -} +FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial -void handleNotFound(){ - String message = "File Not Found\n\n"; - message += "URI: "; - message += server.uri(); - message += "\nMethod: "; - message += (server.method() == HTTP_GET)?"GET":"POST"; - message += "\nArguments: "; - message += server.args(); - message += "\n"; - for (uint8_t i=0; i