Implement FTP Server feature

rewrite the file time access
fix some debug error
add rename function in file systems when available
This commit is contained in:
Luc 2019-10-31 22:29:38 +01:00
parent 0c0a95d6f7
commit c706f44229
30 changed files with 1743 additions and 364 deletions

View File

@ -42,9 +42,6 @@
//TELNET_FEATURE : enable Telnet function
#define TELNET_FEATURE
//FTP_FEATURE : enable FTP function
//#define FTP_FEATURE
//WS_DATA_FEATURE: allow to connect serial from Websocket
#define WS_DATA_FEATURE
@ -112,9 +109,6 @@
//ESP_SDFAT 3 //esp8266 (same as native) / esp32
#define SD_DEVICE ESP_SDFAT
//FILESYSTEM_TIMESTAMP_FEATURE: allow to get last write time from FILESYSTEM files
//#define SD_TIMESTAMP_FEATURE
//pin if reader has insert detection feature
//let -1 or comment if none
#define ESP_SD_DETECT_PIN -1
@ -128,7 +122,14 @@
#define FILESYSTEM_FEATURE ESP_SPIFFS_FILESYSTEM
//Allows to mount /FS and /SD under / for FTP server
#define GLOBAL_FILESYSTEM
#define GLOBAL_FILESYSTEM_FEATURE
//FTP_FEATURE : enable FTP feature
//FS_ROOT mount all FS
//FS_FLASH mount Flash FS
//FS_SD mount SD FS
//FS_USBDISK mount USB disk FS
#define FTP_FEATURE FS_ROOT
//DIRECT_PIN_FEATURE: allow to access pin using ESP201 command
#define DIRECT_PIN_FEATURE
@ -136,9 +137,12 @@
//TIMESTAMP_FEATURE: set time system
//#define TIMESTAMP_FEATURE
//FILESYSTEM_TIMESTAMP_FEATURE: allow to get last write time from FILESYSTEM files
//FILESYSTEM_TIMESTAMP_FEATURE: display last write time from Flash files
//#define FILESYSTEM_TIMESTAMP_FEATURE
//FILESYSTEM_TIMESTAMP_FEATURE:display last write time from SD files
//#define SD_TIMESTAMP_FEATURE
//MDNS_FEATURE: this feature allow type the name defined
//in web browser by default: http:\\esp8266.local and connect
//need `bonjour` protocol on windows

View File

@ -564,7 +564,7 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
response = ESP750(cmd_params, auth_type, output);
break;
#endif //SD_DEVICE
#if defined (GLOBAL_FILESYSTEM)
#if defined (GLOBAL_FILESYSTEM_FEATURE)
//List Global Filesystem
//[ESP780]<Root> pwd=<admin password>
case 780:
@ -576,7 +576,7 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_
case 790:
response = ESP790(cmd_params, auth_type, output);
break;
#endif //GLOBAL_FILESYSTEM
#endif //GLOBAL_FILESYSTEM_FEATURE
//Get fw version firmare target and fw version
//eventually set time with pc time
//output is JSON or plain text according parameter

View File

@ -132,10 +132,10 @@ public:
bool ESP750(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP740(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
#endif //SD_DEVICE
#if defined (GLOBAL_FILESYSTEM)
#if defined (GLOBAL_FILESYSTEM_FEATURE)
bool ESP780(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP790(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
#endif //GLOBAL_FILESYSTEM
#endif //GLOBAL_FILESYSTEM_FEATURE
bool ESP800(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
bool ESP900(const char* cmd_params, level_authenticate_type auth_level, ESP3DOutput * output);
#ifdef BUZZER_DEVICE

View File

@ -23,7 +23,7 @@
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
#include "../../modules/authentication/authentication_service.h"
#include "../../modules/ftp/ftp_server.h"
#include "../../modules/ftp/FtpServer.h"
//Set ftp state which can be ON, OFF, CLOSE
//[ESP180]<state>pwd=<admin password>
bool Commands::ESP180(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)

View File

@ -45,7 +45,7 @@
#include "../../modules/telnet/telnet_server.h"
#endif //TELNET_FEATURE
#ifdef FTP_FEATURE
#include "../../modules/ftp/ftp_server.h"
#include "../../modules/ftp/FtpServer.h"
#endif //FTP_FEATURE
#ifdef WS_DATA_FEATURE
#include "../../modules/websocket/websocket_server.h"

View File

@ -18,7 +18,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (GLOBAL_FILESYSTEM)
#if defined (GLOBAL_FILESYSTEM_FEATURE)
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
@ -107,4 +107,4 @@ bool Commands::ESP780(const char* cmd_params, level_authenticate_type auth_type,
return response;
}
#endif //GLOBAL_FILESYSTEM
#endif //GLOBAL_FILESYSTEM_FEATURE

View File

@ -18,7 +18,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (GLOBAL_FILESYSTEM)
#if defined (GLOBAL_FILESYSTEM_FEATURE)
#include "../commands.h"
#include "../esp3doutput.h"
#include "../settings_esp3d.h"
@ -95,4 +95,4 @@ bool Commands::ESP790(const char* cmd_params, level_authenticate_type auth_type,
return false;
}
#endif //GLOBAL_FILESYSTEM
#endif //GLOBAL_FILESYSTEM_FEATURE

View File

@ -78,8 +78,8 @@
/**************************
* Time
* ***********************/
#if defined(FILESYSTEM_TIMESTAMP_FEATURE) && defined( ARDUINO_ARCH_ESP8266)
#error Filesystem time is not available in ESP8266 yet
#if defined(FILESYSTEM_TIMESTAMP_FEATURE) && defined( ARDUINO_ARCH_ESP8266) && FILESYSTEM_FEATURE == ESP_SPIFFS_FILESYSTEM
#warning Filesystem time is not available in SPIFFS ESP8266 yet
#endif
/**************************

View File

@ -22,7 +22,7 @@
#define _VERSION_ESP3D_H
//version and sources location
#define FW_VERSION "3.0.0.a25"
#define FW_VERSION "3.0.0.a26"
#define REPOSITORY "https://github.com/luc-github/ESP3D"
#endif //_VERSION_ESP3D_H

View File

@ -20,9 +20,7 @@
#include "../../include/esp3d_config.h"
#ifdef FILESYSTEM_FEATURE
#include "esp_filesystem.h"
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
#include <time.h>
#endif //FILESYSTEM_TIMESTAMP_FEATURE
#include <FS.h>
#ifdef ARDUINO_ARCH_ESP32
#include <esp_ota_ops.h>
@ -97,9 +95,7 @@ ESP_File::ESP_File(const char * name, const char * filename, bool isdir, size_t
_index = -1;
_filename = filename;
_name = name;
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = 0;
#endif //FILESYSTEM_TIMESTAMP_FEATURE
_iswritemode = false;
_size = size;
}
@ -144,12 +140,10 @@ size_t ESP_File::size()
return _size;
}
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time_t ESP_File::getLastWrite()
{
return _lastwrite;
}
#endif //FILESYSTEM_TIMESTAMP_FEATURE
int ESP_File::available()
{
@ -210,9 +204,7 @@ ESP_File& ESP_File::operator=(const ESP_File & other)
_size = other._size;
_iswritemode = other._iswritemode;
_dirlist = other._dirlist;
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = other._lastwrite;
#endif //FILESYSTEM_TIMESTAMP_FEATURE
return *this;
}

View File

@ -21,9 +21,7 @@
#ifndef _ESP_FILESYSTEM_H
#define _ESP_FILESYSTEM_H
#include "../../include/esp3d_config.h"
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
#include <time.h>
#endif //FILESYSTEM_TIMESTAMP_FEATURE
#define ESP_FLASH_FS_HEADER "/FS"
@ -43,9 +41,7 @@ public:
bool isOpen();
ESP_File & operator=(const ESP_File & other);
size_t size();
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time_t getLastWrite();
#endif //FILESYSTEM_TIMESTAMP_FEATURE
int available();
size_t write(uint8_t i);
size_t write(const uint8_t *buf, size_t size);
@ -62,9 +58,7 @@ private:
String _filename;
String _name;
size_t _size;
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
time_t _lastwrite;
#endif //FILESYSTEM_TIMESTAMP_FEATURE
};
class ESP_FileSystem
@ -86,6 +80,7 @@ public:
static bool remove(const char *path);
static bool mkdir(const char *path);
static bool rmdir(const char *path);
static bool rename(const char *oldpath, const char *newpath);
static void closeAll();
static bool started()
{

View File

@ -19,9 +19,9 @@
*/
#include "../../include/esp3d_config.h"
#if defined(GLOBAL_FILESYSTEM)
#if defined(GLOBAL_FILESYSTEM_FEATURE)
#include "esp_globalFS.h"
#include "../../core/genLinkedList.h"
//#include "../../core/genLinkedList.h"
//to verify FS is accessible
@ -227,6 +227,27 @@ bool ESP_GBFS::remove(const char *path)
return false;
}
bool ESP_GBFS::rename(const char *oldpath, const char *newpath)
{
#if defined (FILESYSTEM_FEATURE) || defined(SD_DEVICE)
uint8_t t = getFSType(oldpath);
if (t == FS_ROOT) {
return false;
}
#if defined (FILESYSTEM_FEATURE)
if (t == FS_FLASH) {
return ESP_FileSystem::rename(getRealPath(oldpath), getRealPath(newpath));
}
#endif //FILESYSTEM_FEATURE
#if defined (SD_DEVICE)
if (t == FS_SD) {
return ESP_SD::rename(getRealPath(oldpath), getRealPath(newpath));
}
#endif //SD_DEVICE
#endif // FILESYSTEM_FEATURE || SD_DEVICE
return false;
}
bool ESP_GBFS::mkdir(const char *path)
{
#if defined (FILESYSTEM_FEATURE) || defined(SD_DEVICE)
@ -501,22 +522,16 @@ size_t ESP_GBFile::size()
return 0;
}
#if defined (SD_TIMESTAMP_FEATURE) || defined(FILESYSTEM_TIMESTAMP_FEATURE)
time_t ESP_GBFile::getLastWrite()
{
#if defined(FILESYSTEM_FEATURE) && defined(FILESYSTEM_TIMESTAMP_FEATURE)
if (_type == FS_FLASH) {
return _flashFile.getLastWrite();
}
#endif //FILESYSTEM_FEATURE && FILESYSTEM_TIMESTAMP_FEATURE
#if defined(SD_DEVICE) && defined(SD_TIMESTAMP_FEATURE)
if (_type == FS_SD) {
return _sdFile.getLastWrite();
}
#endif //SD_DEVICE && SD_TIMESTAMP_FEATURE
return 0;
}
#endif //SD_TIMESTAMP_FEATURE || FILESYSTEM_TIMESTAMP_FEATURE
int ESP_GBFile::available()
{
@ -716,4 +731,4 @@ ESP_GBFile ESP_GBFile::openNextFile()
return f;
}
#endif //GLOBAL_FILESYSTEM
#endif //GLOBAL_FILESYSTEM_FEATURE

View File

@ -22,9 +22,7 @@
#define _ESP_GLOBAL_FS_H
#include "../../include/esp3d_config.h"
#include "../../core/esp3doutput.h"
#if defined(SD_TIMESTAMP_FEATURE) || defined(FILESYSTEM_TIMESTAMP_FEATURE)
#include <time.h>
#endif //SD_TIMESTAMP_FEATURE || FILESYSTEM_TIMESTAMP_FEATURE
#ifdef FILESYSTEM_FEATURE
#include "esp_filesystem.h"
#endif //FILESYSTEM_FEATURE
@ -60,9 +58,7 @@ public:
ESP_GBFile & operator=(const ESP_SDFile & other);
#endif //SD_DEVICE
size_t size();
#if defined (SD_TIMESTAMP_FEATURE) || defined(FILESYSTEM_TIMESTAMP_FEATURE)
time_t getLastWrite();
#endif //SD_TIMESTAMP_FEATURE || FILESYSTEM_TIMESTAMP_FEATURE
int available();
size_t write(uint8_t i);
size_t write(const uint8_t *buf, size_t size);
@ -96,6 +92,7 @@ public:
static bool remove(const char *path);
static bool mkdir(const char *path);
static bool rmdir(const char *path);
static bool rename(const char *oldpath, const char *newpath);
static void closeAll();
static String & formatBytes (uint64_t bytes);
static const char * getNextFS(bool reset = false);

View File

@ -22,9 +22,7 @@
#ifdef SD_DEVICE
#include "esp_sd.h"
#include "../../core/genLinkedList.h"
#ifdef SD_TIMESTAMP_FEATURE
#include <time.h>
#endif //SD_TIMESTAMP_FEATURE
#define ESP_MAX_SD_OPENHANDLE 4
#if ((SD_DEVICE == ESP_SD_NATIVE) || (SD_DEVICE == ESP_SDFAT)) && defined (ARDUINO_ARCH_ESP8266)
@ -89,9 +87,7 @@ ESP_SDFile::ESP_SDFile(const char * name, const char * filename, bool isdir, siz
_index = -1;
_filename = filename;
_name = name;
#ifdef SD_TIMESTAMP_FEATURE
_lastwrite = 0;
#endif //SD_TIMESTAMP_FEATURE
_iswritemode = false;
_size = size;
}
@ -136,12 +132,10 @@ size_t ESP_SDFile::size()
return _size;
}
#ifdef SD_TIMESTAMP_FEATURE
time_t ESP_SDFile::getLastWrite()
{
return _lastwrite;
}
#endif //SD_TIMESTAMP_FEATURE
int ESP_SDFile::available()
{
@ -201,9 +195,7 @@ ESP_SDFile& ESP_SDFile::operator=(const ESP_SDFile & other)
_size = other._size;
_iswritemode = other._iswritemode;
_dirlist = other._dirlist;
#ifdef SD_TIMESTAMP_FEATURE
_lastwrite = other._lastwrite;
#endif //SD_TIMESTAMP_FEATURE
return *this;
}

View File

@ -22,9 +22,7 @@
#define _ESP_SD_H
#include "../../include/esp3d_config.h"
#include "../../core/esp3doutput.h"
#ifdef SD_TIMESTAMP_FEATURE
#include <time.h>
#endif //SD_TIMESTAMP_FEATURE
#define ESP_SD_FS_HEADER "/SD"
@ -45,9 +43,7 @@ public:
bool isOpen();
ESP_SDFile & operator=(const ESP_SDFile & other);
size_t size();
#ifdef SD_TIMESTAMP_FEATURE
time_t getLastWrite();
#endif //SD_TIMESTAMP_FEATURE
int available();
size_t write(uint8_t i);
size_t write(const uint8_t *buf, size_t size);
@ -63,9 +59,7 @@ private:
String _filename;
String _name;
size_t _size;
#ifdef SD_TIMESTAMP_FEATURE
time_t _lastwrite;
#endif //SD_TIMESTAMP_FEATURE
};
class ESP_SD
@ -89,6 +83,7 @@ public:
static bool remove(const char *path);
static bool mkdir(const char *path);
static bool rmdir(const char *path);
static bool rename(const char *oldpath, const char *newpath);
static void closeAll();
static uint8_t getSPISpeedDivider()
{

View File

@ -53,6 +53,10 @@ size_t ESP_FileSystem::usedBytes()
return (FFat.totalBytes() - FFat.freeBytes());
}
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath)
{
return FFat.rename(oldpath,newpath);
}
const char * ESP_FileSystem::FilesystemName()
{
@ -170,9 +174,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
_index = -1;
_filename = "";
_name = "";
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
memset (&_lastwrite,0,sizeof(time_t));
#endif //FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = 0;
_iswritemode = iswritemode;
_size = 0;
if (!handle) {
@ -218,9 +220,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
//size
_size = tFile_handle[i].size();
//time
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = tFile_handle[i].getLastWrite();
#endif //FILESYSTEM_TIMESTAMP_FEATURE
_index = i;
//log_esp3d("Opening File at index %d",_index);
set = true;
@ -239,9 +239,7 @@ void ESP_File::close()
File ftmp = FFat.open(_filename.c_str());
if (ftmp) {
_size = ftmp.size();
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = ftmp.getLastWrite();
#endif //FILESYSTEM_TIMESTAMP_FEATURE
ftmp.close();
}
}

View File

@ -57,6 +57,10 @@ size_t ESP_FileSystem::usedBytes()
return info.usedBytes;
}
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath)
{
return LittleFS.rename(oldpath,newpath);
}
const char * ESP_FileSystem::FilesystemName()
{
@ -197,9 +201,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
_index = -1;
_filename = "";
_name = "";
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
memset (&_lastwrite,0,sizeof(time_t));
#endif //FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = 0;
_iswritemode = iswritemode;
_size = 0;
if (!handle) {
@ -259,9 +261,9 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
//size
_size = tFile_handle[i].size();
//time
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = tFile_handle[i].getLastWrite();
#endif //FILESYSTEM_TIMESTAMP_FEATURE
//TODO - not yet implemented in esp core
//_lastwrite = tFile_handle[i].getLastWrite();
_lastwrite = 0;
_index = i;
//log_esp3d("Opening File at index %d",_index);
set = true;
@ -286,9 +288,9 @@ void ESP_File::close()
File ftmp = LittleFS.open(_filename.c_str(), "r");
if (ftmp) {
_size = ftmp.size();
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = ftmp.getLastWrite();
#endif //FILESYSTEM_TIMESTAMP_FEATURE
//TODO - not yet implemented in esp core
//_lastwrite = ftmp.getLastWrite();
_lastwrite = 0;
ftmp.close();
}
}

View File

@ -51,6 +51,10 @@ size_t ESP_FileSystem::usedBytes()
return SPIFFS.usedBytes();
}
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath)
{
return SPIFFS.rename(oldpath,newpath);
}
const char * ESP_FileSystem::FilesystemName()
{
@ -185,9 +189,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
_index = -1;
_filename = "";
_name = "";
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
memset (&_lastwrite,0,sizeof(time_t));
#endif //FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = 0;
_iswritemode = iswritemode;
_size = 0;
if (!handle) {
@ -233,9 +235,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
//size
_size = tFile_handle[i].size();
//time
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = tFile_handle[i].getLastWrite();
#endif //FILESYSTEM_TIMESTAMP_FEATURE
_index = i;
//log_esp3d("Opening File at index %d",_index);
set = true;
@ -254,9 +254,7 @@ void ESP_File::close()
File ftmp = SPIFFS.open(_filename.c_str());
if (ftmp) {
_size = ftmp.size();
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = ftmp.getLastWrite();
#endif //FILESYSTEM_TIMESTAMP_FEATURE
ftmp.close();
}
}

View File

@ -55,6 +55,10 @@ size_t ESP_FileSystem::usedBytes()
return info.usedBytes;
}
bool ESP_FileSystem::rename(const char *oldpath, const char *newpath)
{
return SPIFFS.rename(oldpath,newpath);
}
const char * ESP_FileSystem::FilesystemName()
{
@ -178,9 +182,7 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
_index = -1;
_filename = "";
_name = "";
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
memset (&_lastwrite,0,sizeof(time_t));
#endif //FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = 0;
_iswritemode = iswritemode;
_size = 0;
if (!handle) {
@ -263,9 +265,9 @@ ESP_File::ESP_File(void* handle, bool isdir, bool iswritemode, const char * path
//size
_size = tFile_handle[i].size();
//time
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = tFile_handle[i].getLastWrite();
#endif //FILESYSTEM_TIMESTAMP_FEATURE
//TODO - not yet implemented in esp core
//_lastwrite = tFile_handle[i].getLastWrite();
_lastwrite = 0;
_index = i;
//log_esp3d("Opening File at index %d",_index);
set = true;
@ -290,9 +292,9 @@ void ESP_File::close()
File ftmp = SPIFFS.open(_filename.c_str(), "r");
if (ftmp) {
_size = ftmp.size();
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
_lastwrite = ftmp.getLastWrite();
#endif //FILESYSTEM_TIMESTAMP_FEATURE
//TODO - Not yet available in esp core
//_lastwrite = ftmp.getLastWrite();
_lastwrite = 0;
ftmp.close();
}
}

View File

@ -97,7 +97,12 @@ uint64_t ESP_SD::usedBytes()
uint64_t ESP_SD::freeBytes()
{
return (SD.totalBytes() - SD.usedBytes());
};
}
bool ESP_SD::rename(const char *oldpath, const char *newpath)
{
return SD.rename(oldpath,newpath);
}
bool ESP_SD::format(ESP3DOutput * output)
{
@ -213,9 +218,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
_index = -1;
_filename = "";
_name = "";
#ifdef SD_TIMESTAMP_FEATURE
memset (&_lastwrite,0,sizeof(time_t));
#endif //SD_TIMESTAMP_FEATURE
_lastwrite = 0;
_iswritemode = iswritemode;
_size = 0;
if (!handle) {
@ -245,9 +248,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
//size
_size = tSDFile_handle[i].size();
//time
#ifdef SD_TIMESTAMP_FEATURE
_lastwrite = tSDFile_handle[i].getLastWrite();
#endif //SD_TIMESTAMP_FEATURE
_index = i;
//log_esp3d("Opening File at index %d",_index);
set = true;
@ -266,9 +267,7 @@ void ESP_SDFile::close()
File ftmp = SD.open(_filename.c_str());
if (ftmp) {
_size = ftmp.size();
#ifdef SD_TIMESTAMP_FEATURE
_lastwrite = ftmp.getLastWrite();
#endif //SD_TIMESTAMP_FEATURE
ftmp.close();
}
}

View File

@ -31,7 +31,6 @@ using namespace sdfat;
SdFat SD;
#ifdef SD_TIMESTAMP_FEATURE
void dateTime (uint16_t* date, uint16_t* dtime)
{
struct tm tmstruct;
@ -42,12 +41,12 @@ void dateTime (uint16_t* date, uint16_t* dtime)
*dtime = FAT_TIME (tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
}
time_t getDateTimeFile(sdfat::File & filehandle)
time_t getDateTimeFile(File & filehandle)
{
time_t dt = 0;
static time_t dt = 0;
struct tm timefile;
memset((void *)&timefile, 0, sizeof(tm));
dir_t d;
if(filehandle) {
if (filehandle.dirEntry(&d)) {
timefile.tm_year = FAT_YEAR(d.lastWriteDate) - 1900;
timefile.tm_mon = FAT_MONTH(d.lastWriteDate) - 1;
@ -56,20 +55,19 @@ time_t getDateTimeFile(sdfat::File & filehandle)
timefile.tm_min = FAT_MINUTE(d.lastWriteTime);
timefile.tm_sec = FAT_SECOND(d.lastWriteTime);
timefile.tm_isdst = -1;
if (mktime(&timefile) != -1) {
dt = mktime(&timefile);
} else {
if (dt == -1) {
log_esp3d("mktime failed");
}
} else {
log_esp3d("stat file failed");
}
} else {
log_esp3d("check file for stat failed");
}
return dt;
}
#endif //SD_TIMESTAMP_FEATURE
uint8_t ESP_SD::getState(bool refresh)
{
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
@ -143,7 +141,12 @@ uint64_t ESP_SD::freeBytes()
}
uint8_t blocks = SD.vol()->blocksPerCluster();
return volFree * blocks * 512;
};
}
bool ESP_SD::rename(const char *oldpath, const char *newpath)
{
return SD.rename(oldpath,newpath);
}
// strings needed in file system structures
#define noName "NO NAME "
@ -697,9 +700,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
_index = -1;
_filename = "";
_name = "";
#ifdef SD_TIMESTAMP_FEATURE
memset (&_lastwrite,0,sizeof(time_t));
#endif //SD_TIMESTAMP_FEATURE
_lastwrite = 0;
_iswritemode = iswritemode;
_size = 0;
if (!handle) {
@ -732,7 +733,6 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
//size
_size = tSDFile_handle[i].size();
//time
#ifdef SD_TIMESTAMP_FEATURE
if (!_isdir) {
_lastwrite = getDateTimeFile(tSDFile_handle[i]);
@ -740,7 +740,6 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
//no need date time for directory
_lastwrite = 0;
}
#endif //SD_TIMESTAMP_FEATURE
_index = i;
//log_esp3d("Opening File at index %d",_index);
set = true;
@ -772,9 +771,7 @@ void ESP_SDFile::close()
sdfat::File ftmp = SD.open(_filename.c_str());
if (ftmp) {
_size = ftmp.size();
#ifdef SD_TIMESTAMP_FEATURE
_lastwrite = getDateTimeFile(ftmp);
#endif //SD_TIMESTAMP_FEATURE
ftmp.close();
}
}

View File

@ -30,7 +30,6 @@ extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
#define FREQMZ 40
SdFat SD;
#ifdef SD_TIMESTAMP_FEATURE
void dateTime (uint16_t* date, uint16_t* dtime)
{
struct tm tmstruct;
@ -43,10 +42,10 @@ void dateTime (uint16_t* date, uint16_t* dtime)
time_t getDateTimeFile(File & filehandle)
{
time_t dt = 0;
static time_t dt = 0;
struct tm timefile;
memset((void *)&timefile, 0, sizeof(tm));
dir_t d;
if(filehandle) {
if (filehandle.dirEntry(&d)) {
timefile.tm_year = FAT_YEAR(d.lastWriteDate) - 1900;
timefile.tm_mon = FAT_MONTH(d.lastWriteDate) - 1;
@ -55,20 +54,20 @@ time_t getDateTimeFile(File & filehandle)
timefile.tm_min = FAT_MINUTE(d.lastWriteTime);
timefile.tm_sec = FAT_SECOND(d.lastWriteTime);
timefile.tm_isdst = -1;
if (mktime(&timefile) != -1) {
dt = mktime(&timefile);
} else {
if (dt == -1) {
log_esp3d("mktime failed");
}
} else {
log_esp3d("stat file failed");
}
} else {
log_esp3d("check stat file failed");
}
return dt;
}
#endif //SD_TIMESTAMP_FEATURE
uint8_t ESP_SD::getState(bool refresh)
{
#if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1
@ -142,7 +141,12 @@ uint64_t ESP_SD::freeBytes()
}
uint8_t blocks = SD.vol()->blocksPerCluster();
return volFree * blocks * 512;
};
}
bool ESP_SD::rename(const char *oldpath, const char *newpath)
{
return SD.rename(oldpath,newpath);
}
// strings needed in file system structures
#define noName "NO NAME "
@ -696,9 +700,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
_index = -1;
_filename = "";
_name = "";
#ifdef SD_TIMESTAMP_FEATURE
_lastwrite = 0 ;
#endif //SD_TIMESTAMP_FEATURE
_iswritemode = iswritemode;
_size = 0;
if (!handle) {
@ -731,15 +733,13 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
//size
_size = tSDFile_handle[i].size();
//time
#ifdef SD_TIMESTAMP_FEATURE
if (!_isdir) {
if (!_isdir && !iswritemode) {
_lastwrite = getDateTimeFile(tSDFile_handle[i]);
} else {
//no need date time for directory
_lastwrite = 0;
}
#endif //SD_TIMESTAMP_FEATURE
_index = i;
//log_esp3d("Opening File at index %d",_index);
set = true;
@ -771,9 +771,7 @@ void ESP_SDFile::close()
File ftmp = SD.open(_filename.c_str());
if (ftmp) {
_size = ftmp.size();
#ifdef SD_TIMESTAMP_FEATURE
_lastwrite = getDateTimeFile(ftmp);
#endif //SD_TIMESTAMP_FEATURE
ftmp.close();
}
}

View File

@ -86,7 +86,12 @@ uint64_t ESP_SD::usedBytes()
uint64_t ESP_SD::freeBytes()
{
return (SD_MMC.totalBytes() - SD_MMC.usedBytes());
};
}
bool ESP_SD::rename(const char *oldpath, const char *newpath)
{
return SD_MMC.rename(oldpath,newpath);
}
bool ESP_SD::format(ESP3DOutput * output)
{
@ -202,9 +207,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
_index = -1;
_filename = "";
_name = "";
#ifdef SD_TIMESTAMP_FEATURE
memset (&_lastwrite,0,sizeof(time_t));
#endif //SD_TIMESTAMP_FEATURE
_lastwrite = 0;
_iswritemode = iswritemode;
_size = 0;
if (!handle) {
@ -234,9 +237,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char *
//size
_size = tSDFile_handle[i].size();
//time
#ifdef SD_TIMESTAMP_FEATURE
_lastwrite = tSDFile_handle[i].getLastWrite();
#endif //SD_TIMESTAMP_FEATURE
_index = i;
//log_esp3d("Opening File at index %d",_index);
set = true;
@ -255,9 +256,7 @@ void ESP_SDFile::close()
File ftmp = SD_MMC.open(_filename.c_str());
if (ftmp) {
_size = ftmp.size();
#ifdef SD_TIMESTAMP_FEATURE
_lastwrite = ftmp.getLastWrite();
#endif //SD_TIMESTAMP_FEATURE
ftmp.close();
}
}

View File

@ -0,0 +1,127 @@
/*
Streaming.h - Arduino library for supporting the << streaming operator
Copyright (c) 2010-2012 Mikal Hart. All rights reserved.
ExtStreaming.h by Jean-Michel Gallego is a copy of Streaming.h.
endl had been removed and replaced by eol for compatibility with SdFat.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef EXT_STREAMING_H
#define EXT_STREAMING_H
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define STREAMING_LIBRARY_VERSION 5
// Generic template
template<class T>
inline Print &operator <<(Print &stream, T arg)
{
stream.print(arg);
return stream;
}
struct _BASED {
long val;
int base;
_BASED(long v, int b): val(v), base(b)
{}
};
#if ARDUINO >= 100
struct _BYTE_CODE {
byte val;
_BYTE_CODE(byte v) : val(v)
{}
};
#define _BYTE(a) _BYTE_CODE(a)
inline Print &operator <<(Print &obj, const _BYTE_CODE &arg)
{
obj.write(arg.val);
return obj;
}
#else
#define _BYTE(a) _BASED(a, BYTE)
#endif
#define _HEX(a) _BASED(a, HEX)
#define _DEC(a) _BASED(a, DEC)
#define _OCT(a) _BASED(a, OCT)
#define _BIN(a) _BASED(a, BIN)
// Specialization for class _BASED
// Thanks to Arduino forum user Ben Combee who suggested this
// clever technique to allow for expressions like
// Serial << _HEX(a);
inline Print &operator <<(Print &obj, const _BASED &arg)
{
obj.print(arg.val, arg.base);
return obj;
}
#if ARDUINO >= 18
// Specialization for class _FLOAT
// Thanks to Michael Margolis for suggesting a way
// to accommodate Arduino 0018's floating point precision
// feature like this:
// Serial << _FLOAT(gps_latitude, 6); // 6 digits of precision
struct _FLOAT {
float val;
int digits;
_FLOAT(double v, int d): val(v), digits(d)
{}
};
inline Print &operator <<(Print &obj, const _FLOAT &arg)
{
obj.print(arg.val, arg.digits);
return obj;
}
#endif
// Specialization for enum _EndLineCode
// Thanks to Arduino forum user Paul V. who suggested this
// clever technique to allow for expressions like
// Serial << "Hello!" << endl;
/*
enum _EndLineCode { endl };
inline Print &operator <<(Print &obj, _EndLineCode arg)
{ obj.println(); return obj; }
*/
enum _EndLineCode { eol };
inline Print &operator <<(Print &obj, _EndLineCode arg)
{
obj.print( "\r\n" );
return obj;
}
#endif // EXT_STREAMING_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,160 @@
/*
* FTP Serveur for Arduino Due or Mega 2580
* and Ethernet shield W5100, W5200 or W5500
* or for Esp8266 with external SD card or SpiFfs
* Copyright (c) 2014-2018 by Jean-Michel Gallego
*
* 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/>.
*/
/*
* 2019-10-27 Modified version for ESP3D by Luc LEBOSSE @luc-github
* support for ESP8266 and ESP32 in ESP3D project
*/
/*******************************************************************************
** **
** DEFINITIONS FOR FTP SERVER **
** **
*******************************************************************************/
#ifndef FTP_SERVER_H
#define FTP_SERVER_H
class WiFiServer;
class WiFiClient;
#ifndef FF_MAX_LFN
#define FF_MAX_LFN 255
#endif
#define FTP_TIME_OUT 5 * 60 // Disconnect client after 5 minutes of inactivity
#define FTP_AUTH_TIME_OUT 10 // Wait for authentication for 10 seconds
#define FTP_CMD_SIZE FF_MAX_LFN+8 // max size of a command
#define FTP_CWD_SIZE FF_MAX_LFN+8 // max size of a directory name
#define FTP_FIL_SIZE FF_MAX_LFN // max size of a file name
#define FTP_BUF_SIZE 1024 // 512 // size of file buffer for read/write
#define FTP_SERVER WiFiServer
#define FTP_CLIENT WiFiClient
#define CommandIs( a ) (command != NULL && ! strcmp_P( command, PSTR( a )))
#define ParameterIs( a ) ( parameter != NULL && ! strcmp_P( parameter, PSTR( a )))
#include <time.h>
enum ftpCmd { FTP_Stop = 0, // In this stage, stop any connection
FTP_Init, // initialize some variables
FTP_Client, // wait for client connection
FTP_User, // wait for user name
FTP_Pass, // wait for user password
FTP_Cmd
}; // answers to commands
enum ftpTransfer { FTP_Close = 0, // In this stage, close data channel
FTP_Retrieve, // retrieve file
FTP_Store, // store file
FTP_List, // list of files
FTP_Nlst, // list of name of files
FTP_Mlsd
}; // listing for machine processing
enum ftpDataConn { FTP_NoConn = 0,// No data connexion
FTP_Pasive, // Pasive type
FTP_Active
}; // Active type
class FtpServer
{
public:
FtpServer();
~FtpServer();
bool begin();
void handle();
void end();
bool started();
uint16_t ctrlport()
{
return ctrlPort;
}
uint16_t datapassiveport()
{
return passivePort;
}
uint16_t dataactiveport()
{
return activePort;
}
void closeClient();
bool isConnected();
const char* clientIPAddress();
bool isUser(const char * user);
bool isPassword(const char * password);
private:
void iniVariables();
void clientConnected();
void disconnectClient();
bool processCommand();
bool haveParameter();
int dataConnect( bool out150 = true );
bool dataConnected();
bool doRetrieve();
bool doStore();
bool doList();
bool doMlsd();
void closeTransfer();
void abortTransfer();
bool makePath( char * fullName, char * param = NULL );
bool makeExistsPath( char * path, char * param = NULL );
char * makeDateTimeStr( char * tstr, time_t timefile );
char * makeDateTimeString( char * tstr, time_t timefile );
uint8_t getDateTime( char * dt, uint16_t * pyear, uint8_t * pmonth, uint8_t * pday,
uint8_t * phour, uint8_t * pminute, uint8_t * second );
bool getFileModTime(const char * path,time_t & time);
bool timeStamp( const char * path, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second );
int8_t readChar();
FTP_SERVER * ftpServer;
FTP_SERVER * dataServer;
uint16_t ctrlPort; // Command port on wich server is listening
uint16_t activePort; // Default data port in active mode
uint16_t passivePort; // Data port in passive mode
bool _started;
uint8_t _root;
IPAddress dataIp; // IP address of client for data
FTP_CLIENT client;
FTP_CLIENT data;
ftpCmd cmdStage; // stage of ftp command connexion
ftpTransfer transferStage; // stage of data connexion
ftpDataConn dataConn; // type of data connexion
// uint8_t __attribute__((packed, aligned(4))) // need to be aligned to 32bit for Esp8266 SPIClass::transferBytes()
uint8_t buf[ FTP_BUF_SIZE ]; // data buffer for transfers
char cmdLine[ FTP_CMD_SIZE ]; // where to store incoming char from client
char cwdName[ FTP_CWD_SIZE ]; // name of current directory
char rnfrName[ FTP_CWD_SIZE ]; // name of file for RNFR command
char command[ 5 ]; // command sent by client
bool rnfrCmd; // previous command was RNFR
char * parameter; // point to begin of parameters sent by client
uint16_t dataPort;
uint16_t iCL; // pointer to cmdLine next incoming char
uint16_t nbMatch;
uint32_t millisDelay, //
millisEndConnection, //
millisBeginTrans, // store time of beginning of a transaction
bytesTransfered; //
String _currentUser;
};
extern FtpServer ftp_server;
#endif // FTP_SERVER_H

View File

@ -1,142 +0,0 @@
/*
ftp_server.cpp - ftp server functions class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "../../include/esp3d_config.h"
#if defined (FTP_FEATURE)
#include "ftp_server.h"
#include "../../core/settings_esp3d.h"
#include "../../core/esp3doutput.h"
Ftp_Server ftp_server;
void Ftp_Server::closeClient()
{
/*if(_telnetClients) {
_telnetClients.stop();
}*/
}
bool Ftp_Server::isConnected()
{
return false;
/*
if ( !_started || _telnetserver == NULL) {
return false;
}
//check if there are any new clients
if (_telnetserver->hasClient()) {
//find free/disconnected spot
if (!_telnetClients || !_telnetClients.connected()) {
if(_telnetClients) {
_telnetClients.stop();
}
_telnetClients = _telnetserver->available();
//new client
}
}
if (_telnetserver->hasClient()) {
//no free/disconnected spot so reject
_telnetserver->available().stop();
}
return _telnetClients.connected();*/
}
const char* Ftp_Server::clientIPAddress()
{
static String res;
/*res = "0.0.0.0";
if (_telnetClients && _telnetClients.connected()) {
res = _telnetClients.remoteIP().toString();
}*/
return res.c_str();
}
Ftp_Server::Ftp_Server()
{
_started = false;
_ctrlport = 0;
_dataactiveport = 0;
_datapassiveport = 0;
}
Ftp_Server::~Ftp_Server()
{
end();
}
/**
* begin Telnet setup
*/
bool Ftp_Server::begin()
{
end();
if (Settings_ESP3D::read_byte(ESP_TELNET_ON) !=1) {
return true;
}
_ctrlport = Settings_ESP3D::read_uint32(ESP_FTP_CTRL_PORT);
_dataactiveport = Settings_ESP3D::read_uint32(ESP_FTP_DATA_ACTIVE_PORT);
_datapassiveport = Settings_ESP3D::read_uint32(ESP_FTP_DATA_PASSIVE_PORT);
_started = true;
//create instance
/* _telnetserver= new WiFiServer(_port);
if (!_telnetserver) {
return false;
}
_telnetserver->setNoDelay(true);
//start telnet server
_telnetserver->begin();
_started = true;
_lastflush = millis();*/
return _started;
}
/**
* End Telnet
*/
void Ftp_Server::end()
{
_started = false;
_ctrlport = 0;
_dataactiveport = 0;
_datapassiveport = 0;
}
/**
* Reset Telnet
*/
bool Ftp_Server::reset()
{
//nothing to reset
return true;
}
bool Ftp_Server::started()
{
return _started;
}
void Ftp_Server::handle()
{
Hal::wait(0);
//TODO
}
#endif //FTP_FEATURE

View File

@ -1,60 +0,0 @@
/*
ftp_server.h - ftp service functions class
Copyright (c) 2014 Luc Lebosse. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _FTP_SERVER_H
#define _FTP_SERVER_H
class Ftp_Server
{
public:
Ftp_Server();
~Ftp_Server();
bool begin();
void end();
void handle();
bool reset();
bool started();
bool isConnected();
const char* clientIPAddress();
uint16_t ctrlport()
{
return _ctrlport;
}
uint16_t datapassiveport()
{
return _datapassiveport;
}
uint16_t dataactiveport()
{
return _dataactiveport;
}
void closeClient();
private:
bool _started;
uint16_t _ctrlport;
uint16_t _dataactiveport;
uint16_t _datapassiveport;
};
extern Ftp_Server ftp_server;
#endif

View File

@ -270,7 +270,7 @@ uint32_t GcodeHost::Get_commandNumber(String & response)
}
int pos = response.indexOf(sresend);
if (pos == -1 ) {
log_esp3d("Cannot find label", _error);
log_esp3d("Cannot find label %d", _error);
return -1;
}
pos+=sresend.length();

View File

@ -50,7 +50,7 @@
#include "../telnet/telnet_server.h"
#endif //TELNET_FEATURE
#ifdef FTP_FEATURE
#include "../ftp/ftp_server.h"
#include "../ftp/FtpServer.h"
#endif //FP_FEATURE
#ifdef HTTP_FEATURE
#include "../http/http_server.h"