Skip to content

Commit

Permalink
esp8266 less RAM usage
Browse files Browse the repository at this point in the history
  • Loading branch information
gemu2015 committed Jan 3, 2024
1 parent b44b0e0 commit e52388d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/lib_div/FTPServer/library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "FFPServer",
"version": "1.0.0",
"version": "0.1.04",
"keywords": "ftp",
"description": "file transfer protocoll",
"repository":
Expand Down
2 changes: 1 addition & 1 deletion lib/lib_div/FTPServer/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=FFPServer
version=1.0.0
version=0.1.04
author=user robo8080
maintainer=user robo8080
sentence=FTP
Expand Down
72 changes: 43 additions & 29 deletions lib/lib_div/FTPServer/src/FtpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ void FtpServer::handleFTP() {
abortTransfer();
iniVariables();
#ifdef FTP_DEBUG
Serial.println(F("Ftp server waiting for connection on port ") + String(FTP_CTRL_PORT));
Serial.println(F("Ftp server waiting for connection on port ") + String(FTP_CTRL_PORT));
#endif
cmdStatus = 2;
}
else if ( cmdStatus == 2 ) // Ftp server idle
{

if ( client.connected() ) // A client connected
{
if (client.connected() ) {
// A client connected
clientConnected();
millisEndConnection = millis() + 10 * 1000 ; // wait client id during 10 s.
cmdStatus = 3;
Expand All @@ -115,45 +115,51 @@ void FtpServer::handleFTP() {
}
else if ( readChar() > 0 ) // got response
{
if ( cmdStatus == 3 ) // Ftp server waiting for user identity
if ( userIdentity() )

if ( cmdStatus == 3 ) {
// Ftp server waiting for user identity
if (userIdentity()) {
cmdStatus = 4;
else
} else {
cmdStatus = 0;
else if ( cmdStatus == 4 ) // Ftp server waiting for user registration
if ( userPassword() )
{
}
}
else if ( cmdStatus == 4 ) {
// Ftp server waiting for user registration
if (userPassword()) {
cmdStatus = 5;
millisEndConnection = millis() + millisTimeOut;
}
else
} else {
cmdStatus = 0;
else if ( cmdStatus == 5 ) // Ftp server waiting for user command
if( ! processCommand())
}
}
else if ( cmdStatus == 5 ) {
// Ftp server waiting for user command
if (!processCommand()) {
cmdStatus = 0;
else
} else {
millisEndConnection = millis() + millisTimeOut;
}
}
}
else if (!client.connected() || !client)
{
else if (!client.connected() || !client) {
cmdStatus = 1;
#ifdef FTP_DEBUG
Serial.println(F("client disconnected"));
#endif
}

if( transferStatus == 1 ) // Retrieve data
{
if( ! doRetrieve())
if (transferStatus == 1 ) {
// Retrieve data
if (!doRetrieve()) {
transferStatus = 0;
}
else if ( transferStatus == 2 ) // Store data
{
if( ! doStore())
}
} else if ( transferStatus == 2 ) {
// Store data
if (!doStore()) {
transferStatus = 0;
}
else if ( cmdStatus > 2 && ! ((int32_t) ( millisEndConnection - millis() ) > 0 ))
{
}
} else if ( cmdStatus > 2 && ! ((int32_t) ( millisEndConnection - millis() ) > 0 )) {
client.println(F("530 Timeout"));
millisDelay = millis() + 200; // delay of 200 ms
cmdStatus = 0;
Expand Down Expand Up @@ -218,6 +224,11 @@ boolean FtpServer::processCommand() {
// //
///////////////////////////////////////


#ifdef FTP_DEBUG
//Serial.println(F("curr cmd ") + String(command));
#endif

//
// CDUP - Change to Parent Directory
//
Expand Down Expand Up @@ -599,7 +610,7 @@ boolean FtpServer::processCommand() {
//
// STOR - Store
//
else if( ! strcmp( command, "STOR" ))
else if (!strcmp( command, "STOR" ))
{
char path[ FTP_CWD_SIZE ];
if (!haveParameter()) {
Expand Down Expand Up @@ -630,10 +641,13 @@ boolean FtpServer::processCommand() {
// MKD - Make Directory
//

else if( ! strcmp( command, "MKD" ))
else if (!strcmp( command, "MKD" ))
{
char path[ FTP_CWD_SIZE ];
if ( haveParameter() && makePath( path )) {
#ifdef FTP_DEBUG
Serial.println(F("mkdir ") + String(parameters));
#endif
if (haveParameter() && makePath( path )) {
if (ufsp->exists( path )) {
client.println(F("521 Can't create \"") + String(parameters) + F(", Directory exists"));
} else {
Expand Down
14 changes: 10 additions & 4 deletions lib/lib_div/FTPServer/src/FtpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*******************************************************************************/

// Uncomment to print debugging info to console attached to ESP8266
//#define FTP_DEBUG
#define FTP_DEBUG

#ifndef ESP32FTP_SERVERESP_H
#define ESP32FTP_SERVERESP_H
Expand All @@ -48,14 +48,20 @@
#define FTP_DATA_PORT_PASV 50009 // Data port in passive mode

#define FTP_TIME_OUT 5 // Disconnect client after 5 minutes of inactivity

#ifdef ESP32
#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 512 //512 // size of file buffer for read/write
//#define FTP_BUF_SIZE 2*1460 //512 // size of file buffer for read/write
#define FTP_BUF_SIZE 4096 //512 // 700 KByte/s download in AP mode, direct connection.
#endif

#ifdef ESP8266
#define FTP_CMD_SIZE 128 // max size of a command
#define FTP_CWD_SIZE 128 // max size of a directory name
#define FTP_FIL_SIZE 64 // max size of a file name
#define FTP_BUF_SIZE 256 // 700 KByte/s download in AP mode, direct connection.
#endif

class FtpServer
{
Expand Down

0 comments on commit e52388d

Please sign in to comment.