Skip to content

Commit 5aeb17f

Browse files
committed
Minor fix and examples
1 parent 5364f8c commit 5aeb17f

File tree

3 files changed

+332
-0
lines changed

3 files changed

+332
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* FtpServer esp32 with FFat FS
3+
*
4+
* AUTHOR: Renzo Mischianti
5+
*
6+
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
7+
*
8+
*/
9+
10+
#include "Arduino.h"
11+
#include "FS.h"
12+
#include "FFat.h"
13+
14+
#include <SimpleFTPServer.h>
15+
16+
#ifdef STA_MODE
17+
const char* ssid = "<YOUR-SSID>";
18+
const char* password = "<YOUR-PASSWD>";
19+
#endif
20+
const char* ssid_AP = "ESP32";
21+
const char* password_AP = "aabbccdd77";
22+
23+
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
24+
25+
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
26+
switch (ftpOperation) {
27+
case FTP_CONNECT:
28+
Serial.println(F("FTP: Connected!"));
29+
break;
30+
case FTP_DISCONNECT:
31+
Serial.println(F("FTP: Disconnected!"));
32+
break;
33+
case FTP_FREE_SPACE_CHANGE:
34+
Serial.printf("FTP: Free space change, free %u of %u!\n", freeSpace, totalSpace);
35+
break;
36+
default:
37+
break;
38+
}
39+
};
40+
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
41+
switch (ftpOperation) {
42+
case FTP_UPLOAD_START:
43+
Serial.println(F("FTP: Upload start!"));
44+
break;
45+
case FTP_UPLOAD:
46+
Serial.printf("FTP: Upload of file %s byte %u\n", name, transferredSize);
47+
break;
48+
case FTP_TRANSFER_STOP:
49+
Serial.println(F("FTP: Finish transfer!"));
50+
break;
51+
case FTP_TRANSFER_ERROR:
52+
Serial.println(F("FTP: Transfer error!"));
53+
break;
54+
default:
55+
break;
56+
}
57+
58+
/* FTP_UPLOAD_START = 0,
59+
* FTP_UPLOAD = 1,
60+
*
61+
* FTP_DOWNLOAD_START = 2,
62+
* FTP_DOWNLOAD = 3,
63+
*
64+
* FTP_TRANSFER_STOP = 4,
65+
* FTP_DOWNLOAD_STOP = 4,
66+
* FTP_UPLOAD_STOP = 4,
67+
*
68+
* FTP_TRANSFER_ERROR = 5,
69+
* FTP_DOWNLOAD_ERROR = 5,
70+
* FTP_UPLOAD_ERROR = 5
71+
*/
72+
};
73+
74+
void setup(void){
75+
Serial.begin(115200);
76+
77+
//AP mode
78+
WiFi.mode(WIFI_AP);
79+
WiFi.softAP(ssid_AP, password_AP);
80+
delay(1000);
81+
//IPAddress IP = IPAddress (10, 10, 10, 1);
82+
//IPAddress NMask = IPAddress (255, 255, 255, 0);
83+
//WiFi.softAPConfig(IP, IP, NMask);
84+
Serial.print("Set AP named:");
85+
Serial.println(ssid_AP);
86+
IPAddress myIP = WiFi.softAPIP();
87+
Serial.print("AP IP address: ");
88+
Serial.println(myIP);
89+
90+
#ifdef STA_MODE
91+
// STA mode
92+
WiFi.begin(ssid, password);
93+
// Wait for connection
94+
while (WiFi.status() != WL_CONNECTED) {
95+
delay(500);
96+
Serial.print(".");
97+
}
98+
99+
Serial.println("");
100+
Serial.print("Connected to ");
101+
Serial.println(ssid);
102+
Serial.print("IP address: ");
103+
Serial.println(WiFi.localIP());
104+
#endif
105+
106+
/////FTP Setup, ensure FFAT is started before ftp; /////////
107+
Serial.print(F("Inizializing FS..."));
108+
if (FFat.begin(true)){
109+
Serial.println(F("done."));
110+
}else{
111+
Serial.println(F("fail."));
112+
while (true) { delay(1000); };
113+
}
114+
115+
ftpSrv.setCallback(_callback);
116+
ftpSrv.setTransferCallback(_transferCallback);
117+
118+
Serial.println("Start FTP with user: user and passwd: password!");
119+
ftpSrv.begin("user","password"); //username, password for ftp. (default 21, 50009 for PASV)
120+
ftpSrv.setLocalIp(myIP);
121+
}
122+
void loop(void){
123+
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
124+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* FtpServer esp32 with FFat FS
3+
*
4+
* AUTHOR: Renzo Mischianti
5+
*
6+
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
7+
*
8+
*/
9+
10+
#include "Arduino.h"
11+
#include "FS.h"
12+
#include "FFat.h"
13+
14+
#include <SimpleFTPServer.h>
15+
16+
const char* ssid = "<YOUR-SSID>";
17+
const char* password = "<YOUR-PASSWD>";
18+
19+
20+
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
21+
22+
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
23+
switch (ftpOperation) {
24+
case FTP_CONNECT:
25+
Serial.println(F("FTP: Connected!"));
26+
break;
27+
case FTP_DISCONNECT:
28+
Serial.println(F("FTP: Disconnected!"));
29+
break;
30+
case FTP_FREE_SPACE_CHANGE:
31+
Serial.printf("FTP: Free space change, free %u of %u!\n", freeSpace, totalSpace);
32+
break;
33+
default:
34+
break;
35+
}
36+
};
37+
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
38+
switch (ftpOperation) {
39+
case FTP_UPLOAD_START:
40+
Serial.println(F("FTP: Upload start!"));
41+
break;
42+
case FTP_UPLOAD:
43+
Serial.printf("FTP: Upload of file %s byte %u\n", name, transferredSize);
44+
break;
45+
case FTP_TRANSFER_STOP:
46+
Serial.println(F("FTP: Finish transfer!"));
47+
break;
48+
case FTP_TRANSFER_ERROR:
49+
Serial.println(F("FTP: Transfer error!"));
50+
break;
51+
default:
52+
break;
53+
}
54+
55+
/* FTP_UPLOAD_START = 0,
56+
* FTP_UPLOAD = 1,
57+
*
58+
* FTP_DOWNLOAD_START = 2,
59+
* FTP_DOWNLOAD = 3,
60+
*
61+
* FTP_TRANSFER_STOP = 4,
62+
* FTP_DOWNLOAD_STOP = 4,
63+
* FTP_UPLOAD_STOP = 4,
64+
*
65+
* FTP_TRANSFER_ERROR = 5,
66+
* FTP_DOWNLOAD_ERROR = 5,
67+
* FTP_UPLOAD_ERROR = 5
68+
*/
69+
};
70+
71+
void setup(void){
72+
Serial.begin(115200);
73+
WiFi.begin(ssid, password);
74+
Serial.println("");
75+
76+
// Wait for connection
77+
while (WiFi.status() != WL_CONNECTED) {
78+
delay(500);
79+
Serial.print(".");
80+
}
81+
Serial.println("");
82+
Serial.print("Connected to ");
83+
Serial.println(ssid);
84+
Serial.print("IP address: ");
85+
Serial.println(WiFi.localIP());
86+
87+
/////FTP Setup, ensure FFAT is started before ftp; /////////
88+
Serial.print(F("Inizializing FS..."));
89+
if (FFat.begin(true)){
90+
Serial.println(F("done."));
91+
}else{
92+
Serial.println(F("fail."));
93+
while (true) { delay(1000); };
94+
}
95+
96+
ftpSrv.setCallback(_callback);
97+
ftpSrv.setTransferCallback(_transferCallback);
98+
99+
Serial.println("Start FTP with user: user and passwd: password!");
100+
ftpSrv.begin("user","password"); //username, password for ftp. (default 21, 50009 for PASV)
101+
102+
}
103+
void loop(void){
104+
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
105+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* FtpServer Raspberry Pi Pico W with LittleFS
3+
*
4+
* AUTHOR: Renzo Mischianti
5+
*
6+
* https://www.mischianti.org/2020/02/08/ftp-server-on-esp8266-and-esp32
7+
*
8+
*/
9+
10+
#include <WiFi.h>
11+
#include <LittleFS.h>
12+
13+
#include <SimpleFTPServer.h>
14+
15+
const char* ssid = "<YOUR-SSID>";
16+
const char* password = "<YOUR-PASSWD>";
17+
18+
19+
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
20+
21+
void _callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned int totalSpace){
22+
switch (ftpOperation) {
23+
case FTP_CONNECT:
24+
Serial.println(F("FTP: Connected!"));
25+
break;
26+
case FTP_DISCONNECT:
27+
Serial.println(F("FTP: Disconnected!"));
28+
break;
29+
case FTP_FREE_SPACE_CHANGE:
30+
Serial.printf("FTP: Free space change, free %u of %u!\n", freeSpace, totalSpace);
31+
break;
32+
default:
33+
break;
34+
}
35+
};
36+
void _transferCallback(FtpTransferOperation ftpOperation, const char* name, unsigned int transferredSize){
37+
switch (ftpOperation) {
38+
case FTP_UPLOAD_START:
39+
Serial.println(F("FTP: Upload start!"));
40+
break;
41+
case FTP_UPLOAD:
42+
Serial.printf("FTP: Upload of file %s byte %u\n", name, transferredSize);
43+
break;
44+
case FTP_TRANSFER_STOP:
45+
Serial.println(F("FTP: Finish transfer!"));
46+
break;
47+
case FTP_TRANSFER_ERROR:
48+
Serial.println(F("FTP: Transfer error!"));
49+
break;
50+
default:
51+
break;
52+
}
53+
54+
/* FTP_UPLOAD_START = 0,
55+
* FTP_UPLOAD = 1,
56+
*
57+
* FTP_DOWNLOAD_START = 2,
58+
* FTP_DOWNLOAD = 3,
59+
*
60+
* FTP_TRANSFER_STOP = 4,
61+
* FTP_DOWNLOAD_STOP = 4,
62+
* FTP_UPLOAD_STOP = 4,
63+
*
64+
* FTP_TRANSFER_ERROR = 5,
65+
* FTP_DOWNLOAD_ERROR = 5,
66+
* FTP_UPLOAD_ERROR = 5
67+
*/
68+
};
69+
70+
void setup(void){
71+
Serial.begin(115200);
72+
73+
while (!Serial) {delay(100);};
74+
75+
WiFi.begin(ssid, password);
76+
Serial.println("");
77+
78+
// Wait for connection
79+
while (WiFi.status() != WL_CONNECTED) {
80+
delay(500);
81+
Serial.print(".");
82+
}
83+
Serial.println("");
84+
Serial.print("Connected to ");
85+
Serial.println(ssid);
86+
Serial.print("IP address: ");
87+
Serial.println(WiFi.localIP());
88+
89+
90+
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
91+
92+
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
93+
if (LittleFS.begin()) {
94+
ftpSrv.setCallback(_callback);
95+
ftpSrv.setTransferCallback(_transferCallback);
96+
97+
Serial.println("LittleFS opened!");
98+
ftpSrv.begin("user","password"); //username, password for ftp. (default 21, 50009 for PASV)
99+
}
100+
}
101+
void loop(void){
102+
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
103+
}

0 commit comments

Comments
 (0)