Skip to content

Commit

Permalink
Fix anonymous constructor and minor fix on SPIFFS
Browse files Browse the repository at this point in the history
  • Loading branch information
xreef committed Feb 25, 2022
1 parent 1b97b7a commit 2f55438
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 30 deletions.
67 changes: 47 additions & 20 deletions FtpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,11 @@ void FtpServer::begin( const char * _user, const char * _pass, const char * _wel
if( strlen( _user ) > 0 && strlen( _user ) < FTP_CRED_SIZE ) {
//strcpy( user, _user );
this->user = _user;
}else{
// strcpy( user, FTP_USER );
this->user = FTP_USER;
}
if( strlen( _pass ) > 0 && strlen( _pass ) < FTP_CRED_SIZE ) {
// strcpy( pass, _pass );
this->pass = _pass;
}else{
// strcpy( pass, FTP_PASS );
this->pass = FTP_PASS;
}

// strcpy(_welcomeMessage, welcomeMessage);

this->welcomeMessage = _welcomeMessage;
Expand Down Expand Up @@ -124,6 +117,8 @@ void FtpServer::end()
DEBUG_PRINTLN(F("Stop server!"));

cmdStage = FTP_Init;
transferStage = FTP_Close;
dataConn = FTP_NoConn;
}
void FtpServer::setLocalIp(IPAddress localIp)
{
Expand Down Expand Up @@ -1328,16 +1323,44 @@ bool FtpServer::doList()
#endif
{

data.print( F("+r,s") );
#if ESP8266
data.print( long( dir.fileSize()) );
data.print( F(",\t") );
data.println( dir.fileName() );
#else
data.print( long( fileDir.size()) );
data.print( F(",\t") );
data.println( fileDir.name() );
#endif
// data.print( F("+r,s") );
// #if ESP8266
// data.print( long( dir.fileSize()) );
// data.print( F(",\t") );
// data.println( dir.fileName() );
// #else
// data.print( long( fileDir.size()) );
// data.print( F(",\t") );
// data.println( fileDir.name() );
// #endif



#ifdef ESP8266
String fn = dir.fileName();
long fz = long( dir.fileSize());
if (fn[0]=='/') { fn.remove(0, fn.lastIndexOf("/")+1); }
time_t time = dir.fileTime();
generateFileLine(&data, false, fn.c_str(), fz, time, this->user);
#else
long fz = long( fileDir.size());
const char* fnC = fileDir.name();
const char* fn;
if ( fnC[0] == '/' ) {
fn = &fnC[1];
}else{
fn = fnC;
}

time_t time = fileDir.getLastWrite();
generateFileLine(&data, false, fn, fz, time, this->user);

#endif

#ifdef ESP8266
#else
#endif

nbMatch ++;
return true;
}
Expand Down Expand Up @@ -1407,9 +1430,13 @@ bool FtpServer::doList()
// data.print( F(",\t") );
// data.println( dir.fileName() );
#elif STORAGE_TYPE == STORAGE_SEEED_SD
const char* fn = fileDir.name();
fn.remove(0, strlen(dir.name()));
if (fn[0]=='/') { fn.remove(0, fn.lastIndexOf("/")+1); }
const char* fnC = fileDir.name();
const char* fn;
if ( fnC[0] == '/' ) {
fn = &fnC[1];
}else{
fn = fnC;
}
long fz = fileDir.size();
#else
long fz = long( fileDir.size());
Expand Down
5 changes: 1 addition & 4 deletions FtpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,6 @@
#define DEBUG_PRINTLN(...) {}
#endif

#define FTP_USER "arduino" // Default user'name
#define FTP_PASS "test" // Default password

#define FTP_CMD_PORT 21 // Command port on wich server is listening
#define FTP_DATA_PORT_DFLT 20 // Default data port in active mode
#define FTP_DATA_PORT_PASV 50009 // Data port in passive mode
Expand Down Expand Up @@ -458,7 +455,7 @@ class FtpServer
public:
FtpServer( uint16_t _cmdPort = FTP_CMD_PORT, uint16_t _pasvPort = FTP_DATA_PORT_PASV );

void begin( const char * _user = FTP_USER, const char * _pass = FTP_PASS, const char * welcomeMessage = "Welcome to Simply FTP server" );
void begin( const char * _user, const char * _pass, const char * welcomeMessage = "Welcome to Simply FTP server" );
void begin( const char * welcomeMessage = "Welcome to Simply FTP server" );

void end();
Expand Down
6 changes: 3 additions & 3 deletions FtpServerKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define FTP_SERVER_CONFIG_H

// Uncomment to enable printing out nice debug messages.
// #define FTP_SERVER_DEBUG
#define FTP_SERVER_DEBUG

// Define where debug output will be printed.
#define DEBUG_PRINTER Serial
Expand Down Expand Up @@ -46,11 +46,11 @@

#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP8266 NETWORK_ESP8266
#define DEFAULT_STORAGE_TYPE_ESP8266 STORAGE_LITTLEFS
#define DEFAULT_STORAGE_TYPE_ESP8266 STORAGE_SPIFFS
#endif
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32 NETWORK_ESP32
#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_LITTLEFS
#define DEFAULT_STORAGE_TYPE_ESP32 STORAGE_SPIFFS
#endif
#ifndef DEFAULT_FTP_SERVER_NETWORK_TYPE_ARDUINO
#define DEFAULT_FTP_SERVER_NETWORK_TYPE_ARDUINO NETWORK_W5100
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
- Wio Terminal (SdFat 2, and native FAT)

#### Changelog
- 2022-02-22 Add anonymous user and implement correct RFC (#9 now work correctly with File Explorer)
- 2022-02-01 Add workaround to start FTP server before connection, add end and setLocalIP method.
- 2022-02-25 1.2.1 Fix anonymous user begin and fix SPIFFS wrong display
- 2022-02-22 1.2.0 Add anonymous user and implement correct RFC (#9 now work correctly with File Explorer)
- 2022-02-01 1.1.1 Add workaround to start FTP server before connection, add end and setLocalIP method.

<!-- wp:paragraph -->
<p>When I develop a new solution I'd like to divide the application in layer, and so I'd like focus my attention in only one aspect at time. </p>
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SimpleFTPServer
version=1.2.0
version=1.2.1
author=Renzo Mischianti <[email protected]>
maintainer=Renzo Mischianti <[email protected]>
sentence=Simple FTP server for esp8266, esp32 and Arduino
Expand Down

0 comments on commit 2f55438

Please sign in to comment.