diff options
author | nailbuster <david@nailbuster.com> | 2017-10-18 18:59:52 +0200 |
---|---|---|
committer | nailbuster <david@nailbuster.com> | 2017-10-18 18:59:52 +0200 |
commit | 010010f8a1d066a68533e32575370abae16769ae (patch) | |
tree | ed3b9a0a983459e9f77a8e5fb8b56a87e7312d39 | |
parent | Merge pull request #11 from beegee-tokyo/master (diff) | |
download | FTPCLientServer-010010f8a1d066a68533e32575370abae16769ae.tar FTPCLientServer-010010f8a1d066a68533e32575370abae16769ae.tar.gz FTPCLientServer-010010f8a1d066a68533e32575370abae16769ae.tar.bz2 FTPCLientServer-010010f8a1d066a68533e32575370abae16769ae.tar.lz FTPCLientServer-010010f8a1d066a68533e32575370abae16769ae.tar.xz FTPCLientServer-010010f8a1d066a68533e32575370abae16769ae.tar.zst FTPCLientServer-010010f8a1d066a68533e32575370abae16769ae.zip |
-rw-r--r-- | ESP8266FtpServer.cpp | 38 | ||||
-rw-r--r-- | ESP8266FtpServer.h | 4 | ||||
-rw-r--r-- | examples/FTPServerSample/FTPServerSample.ino | 46 | ||||
-rw-r--r-- | library.json | 2 | ||||
-rw-r--r-- | 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 <ESP8266WiFi.h> -#include <ESP8266WebServer.h> #elif defined ESP32 #include <WiFi.h> -#include <Webserver.h> #include "SPIFFS.h" #endif #include <WiFiClient.h> @@ -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 <FS.h> #include <WiFiClient.h> -#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 <ESP8266WiFi.h> -#include <WiFiClient.h> -#include <ESP8266WebServer.h> +#elif defined ESP32 +#include <WiFi.h> +#include "SPIFFS.h" +#endif + #include <ESP8266FtpServer.h> 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<server.args(); i++){ - message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; - } - server.send(404, "text/plain", message); -} void setup(void){ Serial.begin(115200); @@ -48,23 +31,20 @@ void setup(void){ Serial.println(WiFi.localIP()); - server.on("/", handleRoot); - - server.onNotFound(handleNotFound); - - server.begin(); - Serial.println("HTTP server started"); - /////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 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()!! - server.handleClient(); + // server.handleClient(); //example if running a webserver you still need to call .handleClient(); }
diff --git a/library.json b/library.json index bb72342..ff9891f 100644 --- a/library.json +++ b/library.json @@ -11,7 +11,7 @@ "repository": { "type": "git", - "url": "https://github.com/beegee-tokyo/esp8266FTPServer" + "url": "https://github.com/nailbuster/esp8266FTPServer" }, "url": "http://nailbuster.com/", "frameworks": "Arduino", diff --git a/library.properties b/library.properties index d282868..0e89838 100644 --- a/library.properties +++ b/library.properties @@ -6,4 +6,4 @@ sentence=Very Simple FTP server for SPIFFS on esp8266 paragraph=Very Simple FTP server for SPIFFS on esp8266 category=Communication url= -architectures=esp8266 +architectures=esp8266,esp32,arduino-esp32 |