1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*
* FTP SERVER FOR ESP8266/ESP32
* based on FTP Serveur for Arduino Due and Ethernet shield (W5100) or WIZ820io (W5200)
* based on Jean-Michel Gallego's work
* modified to work with esp8266 SPIFFS by David Paiva (david@nailbuster.com)
* modified to work with esp8266 LitteFS by Daniel Plasa dplasa@gmail.com
* Also done some code reworks and all string contants are now in flash memory
* by using F(), PSTR() ... on the string literals.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FTP_SERVER_H
#define FTP_SERVER_H
/*******************************************************************************
** **
** DEFINITIONS FOR FTP SERVER/CLIENT **
** **
*******************************************************************************/
#include "FTPCommon.h"
#define FTP_SERVER_VERSION "0.9.3-20200526"
class FTPServer : public FTPCommon
{
public:
// contruct an instance of the FTP server using a
// given FS object, e.g. SPIFFS or LittleFS
FTPServer(FS &_FSImplementation);
// starts the FTP server with username and password,
// either one can be empty to enable anonymous ftp
void begin(const String &uname, const String &pword);
// stops the FTP server
void stop();
// set the FTP server's timeout in seconds
void setTimeout(uint16_t timeout = FTP_TIME_OUT * 60);
// needs to be called frequently (e.g. in loop() )
// to process ftp requests
void handleFTP();
private:
enum internalState
{
cInit = 0,
cWait,
cCheck,
cUserId,
cPassword,
cLoginOk,
cProcess,
tIdle,
tRetrieve,
tStore
};
void iniVariables();
void disconnectClient(bool gracious = true);
int8_t processCommand();
virtual void closeTransfer();
void abortTransfer();
virtual int8_t dataConnect();
String getPathName(const String ¶m, bool includeLast = false);
String getFileName(const String ¶m, bool fullFilePath = false);
String makeDateTimeStr(time_t fileTime);
int8_t readChar();
void updateTimeout(uint16_t timeout);
// server specific
bool dataPassiveConn = true; // PASV (passive) mode is our default
String _FTP_USER; // usename
String _FTP_PASS; // password
uint32_t command; // numeric command code of command sent by the client
String cmdLine; // command line as read from client
String cmdString; // command as textual representation
String parameters; // parameters sent by client
String cwd; // the current directory
String rnFrom; // previous command was RNFR, this is the source file name
internalState cmdState, // state of ftp control connection
transferState; // state of ftp data connection
uint32_t millisEndConnection;
};
#endif // FTP_SERVER_H
|