FTP Server
The FtpServer class implements a simple FTP server. It accepts new connections and spawns a new FtpClientSession for each one. Each session is handled in its own thread.
The FtpClientSession class implements the FTP protocol. It is responsible for handling the commands and sending the responses.
Note that the FTP server does not implement any authentication mechanism. It accepts any username and password.
API Reference
Header File
Classes
-
class FtpServer : public espp::BaseComponent
A class that implements a FTP server.
Public Functions
-
inline FtpServer(std::string_view ip_address, uint16_t port, const std::filesystem::path &root)
A class that implements a FTP server.
Note
The IP Address is not currently used to select the right interface, but is instead passed to the FtpClientSession so that it can be used in the PASV command.
- Parameters
ip_address – The IP address to listen on.
port – The port to listen on.
root – The root directory of the FTP server.
-
inline ~FtpServer()
Destroy the FTP server.
-
inline bool start()
Start the FTP server. Bind to the port and start accepting connections.
- Returns
True if the server was started, false otherwise.
-
inline void stop()
Stop the FTP server.
-
inline const std::string &get_name() const
Get the name of the component
Note
This is the tag of the logger
- Returns
A const reference to the name of the component
-
inline void set_log_tag(const std::string_view &tag)
Set the tag for the logger
- Parameters
tag – The tag to use for the logger
-
inline espp::Logger::Verbosity get_log_level() const
Get the log level for the logger
See also
See also
- Returns
The verbosity level of the logger
-
inline void set_log_level(espp::Logger::Verbosity level)
Set the log level for the logger
See also
See also
- Parameters
level – The verbosity level to use for the logger
-
inline void set_log_verbosity(espp::Logger::Verbosity level)
Set the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls set_log_level
- Parameters
level – The verbosity level to use for the logger
-
inline espp::Logger::Verbosity get_log_verbosity() const
Get the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls get_log_level
- Returns
The verbosity level of the logger
-
inline void set_log_rate_limit(std::chrono::duration<float> rate_limit)
Set the rate limit for the logger
See also
Note
Only calls to the logger that have _rate_limit suffix will be rate limited
- Parameters
rate_limit – The rate limit to use for the logger
-
inline FtpServer(std::string_view ip_address, uint16_t port, const std::filesystem::path &root)
Header File
Classes
-
class FtpClientSession : public espp::BaseComponent
Class representing a client that is connected to the FTP server. This class is used by the FtpServer class to handle the client’s requests.
Public Functions
-
inline int id() const
Get the id of the client session.
- Returns
The id of the client session.
-
inline std::filesystem::path current_directory() const
Get the current directory of the client session.
- Returns
The current directory of the client session.
-
inline bool is_connected() const
Check if the client session has a valid control connection.
This function checks if the client session has a valid control connection. A control connection is valid if the control socket is valid and connected.
- Returns
True if the control connection is valid, false otherwise.
-
inline bool is_passive_data_connection() const
Check if the client is using a passive data connection.
This function checks if the client is using a passive data connection. A client is using a passive data connection if the client has sent a PASV command and the session was able to create a passive socket.
- Returns
True if the client is using a passive data connection, false otherwise.
-
inline bool is_alive() const
Check if the client session is alive.
This function checks if the client session is alive. A client session is alive if the task is running.
- Returns
True if the client session is alive, false otherwise.
-
inline const std::string &get_name() const
Get the name of the component
Note
This is the tag of the logger
- Returns
A const reference to the name of the component
-
inline void set_log_tag(const std::string_view &tag)
Set the tag for the logger
- Parameters
tag – The tag to use for the logger
-
inline espp::Logger::Verbosity get_log_level() const
Get the log level for the logger
See also
See also
- Returns
The verbosity level of the logger
-
inline void set_log_level(espp::Logger::Verbosity level)
Set the log level for the logger
See also
See also
- Parameters
level – The verbosity level to use for the logger
-
inline void set_log_verbosity(espp::Logger::Verbosity level)
Set the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls set_log_level
- Parameters
level – The verbosity level to use for the logger
-
inline espp::Logger::Verbosity get_log_verbosity() const
Get the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls get_log_level
- Returns
The verbosity level of the logger
-
inline void set_log_rate_limit(std::chrono::duration<float> rate_limit)
Set the rate limit for the logger
See also
Note
Only calls to the logger that have _rate_limit suffix will be rate limited
- Parameters
rate_limit – The rate limit to use for the logger
-
inline int id() const