From 8be389a08d1cd38ac1761110768e8442b877d334 Mon Sep 17 00:00:00 2001 From: anschrammh Date: Sat, 19 Dec 2020 21:04:11 +0100 Subject: [PATCH] Removed the dependency to definition.h as well as replacing SDCardManager class parameter to SDClass parameter --- src/app/FTPServer.h | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/app/FTPServer.h b/src/app/FTPServer.h index f1a380f..0851018 100644 --- a/src/app/FTPServer.h +++ b/src/app/FTPServer.h @@ -1,9 +1,9 @@ #ifndef FTPSERVER_H #define FTPSERVER_H +#include #include "TCPServer.h" -#include "SDCardManager.h" -#include "definition.h" +#include "utilities.h" #include "Dictionary.h" //#define DEBUG_FTPS #define READ_BUFFER_SIZE 2048 //2048 is max to read sd card, more will crash @@ -18,12 +18,12 @@ class FTPServer : public TCPServer enum BinaryFlag {OFF = 0, ON}; enum FtpMsgCode {_150, _200, _215, _220, _221, _230, _226, _227, _250, _257, _331, _350, _451, _5_502, _504, _530, _550 }; - FTPServer(uint16_t port = 21, SDCardManager *sdCardManager = NULL, const char *login = NULL, const char *password = NULL, uint8_t maxClient = MAX_CLIENT, uint16_t clientCommandDataBufferSize = 255) : TCPServer(port, maxClient, clientCommandDataBufferSize), + FTPServer(uint16_t port = 21, SDClass *sdClass = NULL, const char *login = NULL, const char *password = NULL, uint8_t maxClient = MAX_CLIENT, uint16_t clientCommandDataBufferSize = 255) : TCPServer(port, maxClient, clientCommandDataBufferSize), _login(NULL), _password(NULL), _dataPort(1024), _dataServer(_dataPort), - _sdCardManager(sdCardManager) + _sdClass(sdClass) { if (login != NULL) { @@ -65,6 +65,11 @@ class FTPServer : public TCPServer } } + virtual void setFTPDir(const char *FTPDir) + { + _FTPDir = FTPDir; + } + protected: virtual T* createNewClient(WiFiClient wc) { @@ -191,10 +196,10 @@ class FTPServer : public TCPServer { if(client->_fileRecvBytes == 0) //File was just created empty { - if(_sdCardManager->exists(client->_currentFile)) - _sdCardManager->remove(client->_currentFile); + if(_sdClass->exists(client->_currentFile)) + _sdClass->remove(client->_currentFile); - File file2create = _sdCardManager->open(client->_currentFile, FILE_WRITE); + File file2create = _sdClass->open(client->_currentFile, FILE_WRITE); file2create.close(); #ifdef DEBUG_FTPS @@ -275,7 +280,7 @@ class FTPServer : public TCPServer processCommands(client); break; case INIT: - client->setCurrentDirectory(FTP_DIR); + _FTPDir ? client->setCurrentDirectory(_FTPDir) : client->setCurrentDirectory(""); client->_ftpClientState = WAITING_FOR_COMMANDS; break; } @@ -555,7 +560,7 @@ class FTPServer : public TCPServer Serial.printf("Final dirName : #%s#\n",dirNameWithPath); #endif - if(_sdCardManager->mkdir(dirNameWithPath)) + if(_sdClass->mkdir(dirNameWithPath)) { client->_client.printf("257 \"%s\"\r\n", dirNameWithPath); } @@ -591,7 +596,7 @@ class FTPServer : public TCPServer Serial.printf("pathDirName to delete : #%s#\n",dirNameWithPath); #endif - if(_sdCardManager->rmdir(dirNameWithPath)) + if(_sdClass->rmdir(dirNameWithPath)) { client->_client.println("250 Requested file action okay."); } @@ -677,7 +682,7 @@ class FTPServer : public TCPServer Serial.printf("file to delete : #%s#\n",file2deleteNameWithPath); #endif - if(_sdCardManager->remove(file2deleteNameWithPath)) + if(_sdClass->remove(file2deleteNameWithPath)) { client->_client.println("250 Requested file action okay."); } @@ -747,7 +752,7 @@ class FTPServer : public TCPServer Serial.printf("Old name : %s --> %s\n",client->_currentFile,file2RenameNameWithPath); #endif - if(_sdCardManager->rename(client->_currentFile,file2RenameNameWithPath)) + if(_sdClass->rename(client->_currentFile,file2RenameNameWithPath)) { client->_client.println("250 Requested file action okay."); }else @@ -789,10 +794,10 @@ class FTPServer : public TCPServer { if (client->_currentFile != NULL) { - if(_sdCardManager->exists(client->_currentFile) && client->_fileRecvBytes == 0 && !append) - _sdCardManager->remove(client->_currentFile); + if(_sdClass->exists(client->_currentFile) && client->_fileRecvBytes == 0 && !append) + _sdClass->remove(client->_currentFile); - File fileBeeingReceived = _sdCardManager->open(client->_currentFile, FILE_WRITE); + File fileBeeingReceived = _sdClass->open(client->_currentFile, FILE_WRITE); if(fileBeeingReceived) { @@ -830,7 +835,7 @@ class FTPServer : public TCPServer #ifdef DEBUG_FTPS Serial.printf("Directory : %s\n",client->_currentDirectory); #endif - File currentDirectory = _sdCardManager->open(client->_currentDirectory); + File currentDirectory = _sdClass->open(client->_currentDirectory); if (currentDirectory) { currentDirectory.rewindDirectory(); @@ -886,7 +891,7 @@ class FTPServer : public TCPServer if (client->_currentFile != NULL) { uint8_t sendBuffer[READ_BUFFER_SIZE]; - File fileToSend = _sdCardManager->open(client->_currentFile); + File fileToSend = _sdClass->open(client->_currentFile); if (fileToSend) { @@ -992,10 +997,11 @@ class FTPServer : public TCPServer char *_login; char *_password; + const char *_FTPDir = NULL; //Pointer to constant string and char * cont is a constant pointer to string uint16_t _dataPort; WiFiServer _dataServer; //In passive mode, the FTP server opens two different ports (one for the commands and the other for the data stream) - SDCardManager *_sdCardManager; + SDClass *_sdClass; }; #endif //FTPSERVER_H