Removed the dependency to definition.h as well as replacing SDCardManager class parameter to SDClass parameter
This commit is contained in:
parent
573e33ccf4
commit
8be389a08d
@ -1,9 +1,9 @@
|
||||
#ifndef FTPSERVER_H
|
||||
#define FTPSERVER_H
|
||||
|
||||
#include <SD.h>
|
||||
#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<T>
|
||||
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<T>(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<T>(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<T>
|
||||
}
|
||||
}
|
||||
|
||||
virtual void setFTPDir(const char *FTPDir)
|
||||
{
|
||||
_FTPDir = FTPDir;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual T* createNewClient(WiFiClient wc)
|
||||
{
|
||||
@ -191,10 +196,10 @@ class FTPServer : public TCPServer<T>
|
||||
{
|
||||
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<T>
|
||||
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<T>
|
||||
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<T>
|
||||
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<T>
|
||||
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<T>
|
||||
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<T>
|
||||
{
|
||||
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<T>
|
||||
#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<T>
|
||||
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<T>
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user