ESPFtpServer.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * FTP SERVER FOR ESP8266
  3. * based on FTP Serveur for Arduino Due and Ethernet shield (W5100) or WIZ820io (W5200)
  4. * based on Jean-Michel Gallego's work
  5. * modified to work with esp8266 SPIFFS by David Paiva (david@nailbuster.com)
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /*******************************************************************************
  21. ** **
  22. ** DEFINITIONS FOR FTP SERVER **
  23. ** **
  24. *******************************************************************************/
  25. // Uncomment to print debugging info to console attached to ESP8266
  26. //#define FTP_DEBUG
  27. #ifndef FTP_SERVERESP_H
  28. #define FTP_SERVERESP_H
  29. #include <SdFat.h>
  30. #include <WiFiClient.h>
  31. #include "Version.h"
  32. #define FTP_DEBUG 1
  33. #define FTP_SERVER_VERSION GOTEK_VERSION
  34. #define FTP_CTRL_PORT 21 // Command port on wich server is listening
  35. #define FTP_DATA_PORT_PASV 50009 // Data port in passive mode
  36. #define FTP_TIME_OUT 5 // Disconnect client after 5 minutes of inactivity
  37. #define FTP_CMD_SIZE 255 + 8 // max size of a command
  38. #define FTP_CWD_SIZE 255 + 8 // max size of a directory name
  39. #define FTP_FIL_SIZE 255 // max size of a file name
  40. //#define FTP_BUF_SIZE 1024 //512 // size of file buffer for read/write
  41. //#define FTP_BUF_SIZE 8*1460
  42. #define FTP_BUF_SIZE 1024
  43. extern SPISettings spiSettings;
  44. class FtpServer
  45. {
  46. public:
  47. void begin(String uname, String pword, int chipSelectPin, SPISettings spiSettings);
  48. void handleFTP();
  49. int8_t cmdStatus,SD_Status; // status of ftp command connexion
  50. private:
  51. void iniVariables();
  52. void clientConnected();
  53. void disconnectClient();
  54. boolean userIdentity();
  55. boolean userPassword();
  56. boolean processCommand();
  57. boolean dataConnect();
  58. boolean doRetrieve();
  59. boolean doStore();
  60. void closeTransfer();
  61. void abortTransfer();
  62. boolean makePath( char * fullname );
  63. boolean makePath( char * fullName, char * param );
  64. uint8_t getDateTime( uint16_t * pyear, uint8_t * pmonth, uint8_t * pday,
  65. uint8_t * phour, uint8_t * pminute, uint8_t * second );
  66. char * makeDateTimeStr( char * tstr, uint16_t date, uint16_t time );
  67. int8_t readChar();
  68. bool initSD();
  69. IPAddress dataIp; // IP address of client for data
  70. WiFiClient client;
  71. WiFiClient data;
  72. FatFile file;
  73. SdFat SD;
  74. int chipSelectPin;
  75. SPISettings spiSettings;
  76. boolean dataPassiveConn;
  77. uint16_t dataPort;
  78. char buf[ FTP_BUF_SIZE ]; // data buffer for transfers
  79. char cmdLine[ FTP_CMD_SIZE ]; // where to store incoming char from client
  80. char cwdName[ FTP_CWD_SIZE ]; // name of current directory
  81. char command[ 5 ]; // command sent by client
  82. boolean rnfrCmd; // previous command was RNFR
  83. char * parameters; // point to begin of parameters sent by client
  84. uint16_t iCL; // pointer to cmdLine next incoming char
  85. int8_t transferStatus; // status of ftp data transfer
  86. uint32_t millisTimeOut, // disconnect after 5 min of inactivity
  87. millisDelay,
  88. millisEndConnection, //
  89. millisBeginTrans, // store time of beginning of a transaction
  90. bytesTransfered; //
  91. String _FTP_USER;
  92. String _FTP_PASS;
  93. // SD stuff
  94. //bool isSDInit = false;
  95. };
  96. #endif // FTP_SERVERESP_H