FtpServer.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * FtpServer.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "TcpServer.h"
14 #include "WHashMap.h"
15 #include <FileSystem.h>
16 
18 
23 class CustomFtpServer : public TcpServer
24 {
25  friend class FtpServerConnection;
26 
27 public:
28  CustomFtpServer(IFS::FileSystem* fileSystem = nullptr) : fileSystem(fileSystem)
29  {
30  setTimeOut(900);
31  }
32 
39  virtual IFS::UserRole validateUser(const char* login, const char* pass) = 0;
40 
41 protected:
42  TcpConnection* createClient(tcp_pcb* clientTcp) override;
43 
51  virtual bool onCommand(String cmd, String data, FtpServerConnection& connection)
52  {
53  return false;
54  }
55 
57  {
58  return fileSystem ?: ::getFileSystem();
59  }
60 
61 private:
62  IFS::FileSystem* fileSystem;
63 };
64 
69 class FtpServer : public CustomFtpServer
70 {
71 public:
72  void addUser(const String& login, const String& pass, IFS::UserRole userRole = IFS::UserRole::Admin);
73  IFS::UserRole validateUser(const char* login, const char* pass) override;
74 
75 protected:
76  bool onCommand(String cmd, String data, FtpServerConnection& connection) override;
77 
78 private:
79  struct User {
80  String password;
81  IFS::UserRole role;
82  };
84  UserList users;
85 };
Definition: FtpServerConnection.h:27
IFS::FileSystem * getFileSystem() const
Definition: FtpServer.h:56
The String class.
Definition: WString.h:136
void setTimeOut(uint16_t waitTimeOut)
virtual bool onCommand(String cmd, String data, FtpServerConnection &connection)
Handle an incoming command.
Definition: FtpServer.h:51
virtual IFS::UserRole validateUser(const char *login, const char *pass)=0
Validate user.
Installable File System base class.
Definition: Components/IFS/src/include/IFS/FileSystem.h:39
Definition: TcpServer.h:30
UserRole
Definition: UserRole.h:55
TcpConnection * createClient(tcp_pcb *clientTcp) override
void addUser(const String &login, const String &pass, IFS::UserRole userRole=IFS::UserRole::Admin)
bool onCommand(String cmd, String data, FtpServerConnection &connection) override
Handle an incoming command.
IFS::UserRole validateUser(const char *login, const char *pass) override
Validate user.
Definition: TcpConnection.h:39
Provides FTP server.
Definition: FtpServer.h:69
Definition: FtpServer.h:23
CustomFtpServer(IFS::FileSystem *fileSystem=nullptr)
Definition: FtpServer.h:28