diff options
Diffstat (limited to 'examples/FTPServerSample')
-rw-r--r-- | examples/FTPServerSample/FTPServerSample.ino | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/examples/FTPServerSample/FTPServerSample.ino b/examples/FTPServerSample/FTPServerSample.ino new file mode 100644 index 0000000..06223df --- /dev/null +++ b/examples/FTPServerSample/FTPServerSample.ino @@ -0,0 +1,70 @@ +#include <ESP8266WiFi.h> +#include <WiFiClient.h> +#include <ESP8266WebServer.h> +#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!"); + +} + +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); + 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()); + + + server.on("/", handleRoot); + + server.onNotFound(handleNotFound); + + server.begin(); + Serial.println("HTTP server started"); + + /////FTP Setup, ensure SPIFFS is started before ftp; ///////// + + 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) + } +} + +void loop(void){ + ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!! + server.handleClient(); + +}
|