Go to the documentation of this file.
40 #ifndef FTP_SERVER_SUPPORT
41 #define FTP_SERVER_SUPPORT ENABLED
42 #elif (FTP_SERVER_SUPPORT != ENABLED && FTP_SERVER_SUPPORT != DISABLED)
43 #error FTP_SERVER_SUPPORT parameter is not valid
47 #ifndef FTP_SERVER_TLS_SUPPORT
48 #define FTP_SERVER_TLS_SUPPORT DISABLED
49 #elif (FTP_SERVER_TLS_SUPPORT != ENABLED && FTP_SERVER_TLS_SUPPORT != DISABLED)
50 #error FTP_SERVER_TLS_SUPPORT parameter is not valid
54 #ifndef FTP_SERVER_STACK_SIZE
55 #define FTP_SERVER_STACK_SIZE 650
56 #elif (FTP_SERVER_STACK_SIZE < 1)
57 #error FTP_SERVER_STACK_SIZE parameter is not valid
61 #ifndef FTP_SERVER_PRIORITY
62 #define FTP_SERVER_PRIORITY OS_TASK_PRIORITY_NORMAL
66 #ifndef FTP_SERVER_MAX_CONNECTIONS
67 #define FTP_SERVER_MAX_CONNECTIONS 10
68 #elif (FTP_SERVER_MAX_CONNECTIONS < 1)
69 #error FTP_SERVER_MAX_CONNECTIONS parameter is not valid
73 #ifndef FTP_SERVER_TIMEOUT
74 #define FTP_SERVER_TIMEOUT 60000
75 #elif (FTP_SERVER_TIMEOUT < 1000)
76 #error FTP_SERVER_TIMEOUT parameter is not valid
80 #ifndef FTP_SERVER_TICK_INTERVAL
81 #define FTP_SERVER_TICK_INTERVAL 1000
82 #elif (FTP_SERVER_TICK_INTERVAL < 100)
83 #error FTP_SERVER_TICK_INTERVAL parameter is not valid
87 #ifndef FTP_SERVER_BACKLOG
88 #define FTP_SERVER_BACKLOG 4
89 #elif (FTP_SERVER_BACKLOG < 1)
90 #error FTP_SERVER_BACKLOG parameter is not valid
94 #ifndef FTP_SERVER_MAX_LINE_LEN
95 #define FTP_SERVER_MAX_LINE_LEN 255
96 #elif (FTP_SERVER_MAX_LINE_LEN < 64)
97 #error FTP_SERVER_MAX_LINE_LEN parameter is not valid
101 #ifndef FTP_SERVER_BUFFER_SIZE
102 #define FTP_SERVER_BUFFER_SIZE 1024
103 #elif (FTP_SERVER_BUFFER_SIZE < 128)
104 #error FTP_SERVER_BUFFER_SIZE parameter is not valid
108 #ifndef FTP_SERVER_MAX_ROOT_DIR_LEN
109 #define FTP_SERVER_MAX_ROOT_DIR_LEN 63
110 #elif (FTP_SERVER_MAX_ROOT_DIR_LEN < 7)
111 #error FTP_SERVER_MAX_ROOT_DIR_LEN parameter is not valid
115 #ifndef FTP_SERVER_MAX_HOME_DIR_LEN
116 #define FTP_SERVER_MAX_HOME_DIR_LEN 63
117 #elif (FTP_SERVER_MAX_HOME_DIR_LEN < 7)
118 #error FTP_SERVER_MAX_HOME_DIR_LEN parameter is not valid
122 #ifndef FTP_SERVER_MAX_USERNAME_LEN
123 #define FTP_SERVER_MAX_USERNAME_LEN 63
124 #elif (FTP_SERVER_MAX_USERNAME_LEN < 7)
125 #error FTP_SERVER_MAX_USERNAME_LEN parameter is not valid
129 #ifndef FTP_SERVER_MAX_PATH_LEN
130 #define FTP_SERVER_MAX_PATH_LEN 255
131 #elif (FTP_SERVER_MAX_PATH_LEN < 7)
132 #error FTP_SERVER_MAX_PATH_LEN parameter is not valid
136 #ifndef FTP_SERVER_MIN_TCP_BUFFER_SIZE
137 #define FTP_SERVER_MIN_TCP_BUFFER_SIZE 1430
138 #elif (FTP_SERVER_MIN_TCP_BUFFER_SIZE < 512)
139 #error FTP_SERVER_MIN_TCP_BUFFER_SIZE parameter is not valid
143 #ifndef FTP_SERVER_MAX_TCP_BUFFER_SIZE
144 #define FTP_SERVER_MAX_TCP_BUFFER_SIZE 2860
145 #elif (FTP_SERVER_MAX_TCP_BUFFER_SIZE < 512)
146 #error FTP_SERVER_MAX_TCP_BUFFER_SIZE parameter is not valid
150 #ifndef FTP_SERVER_TLS_TX_BUFFER_SIZE
151 #define FTP_SERVER_TLS_TX_BUFFER_SIZE 4096
152 #elif (FTP_SERVER_TLS_TX_BUFFER_SIZE < 512)
153 #error FTP_SERVER_TLS_TX_BUFFER_SIZE parameter is not valid
157 #ifndef FTP_SERVER_MIN_TLS_RX_BUFFER_SIZE
158 #define FTP_SERVER_MIN_TLS_RX_BUFFER_SIZE 2048
159 #elif (FTP_SERVER_MIN_TLS_RX_BUFFER_SIZE < 512)
160 #error FTP_SERVER_MIN_TLS_RX_BUFFER_SIZE parameter is not valid
164 #ifndef FTP_SERVER_MAX_TLS_RX_BUFFER_SIZE
165 #define FTP_SERVER_MAX_TLS_RX_BUFFER_SIZE 16384
166 #elif (FTP_SERVER_MAX_TLS_RX_BUFFER_SIZE < 512)
167 #error FTP_SERVER_MAX_TLS_RX_BUFFER_SIZE parameter is not valid
171 #ifndef FTP_SERVER_PASSIVE_PORT_MIN
172 #define FTP_SERVER_PASSIVE_PORT_MIN 48128
173 #elif (FTP_SERVER_PASSIVE_PORT_MIN < 1024)
174 #error FTP_SERVER_PASSIVE_PORT_MIN parameter is not valid
178 #ifndef FTP_SERVER_PASSIVE_PORT_MAX
179 #define FTP_SERVER_PASSIVE_PORT_MAX 49151
180 #elif (FTP_SERVER_PASSIVE_PORT_MAX <= FTP_SERVER_PASSIVE_PORT_MIN || FTP_SERVER_PASSIVE_PORT_MAX > 65535)
181 #error FTP_SERVER_PASSIVE_PORT_MAX parameter is not valid
185 #ifndef FTP_SERVER_PRIVATE_CONTEXT
186 #define FTP_SERVER_PRIVATE_CONTEXT
190 #if (FTP_SERVER_TLS_SUPPORT == ENABLED)
199 #define FTP_DATA_PORT 20
202 #define FTPS_PORT 990
204 #define FTPS_DATA_PORT 989
208 #define FtpServerContext struct _FtpServerContext
212 #define FtpClientConnection struct _FtpClientConnection
290 const IpAddr *clientIpAddr, uint16_t clientPort);
298 const IpAddr *clientIpAddr, uint16_t clientPort);
302 #if (FTP_SERVER_TLS_SUPPORT == ENABLED)
365 #if (FTP_SERVER_TLS_SUPPORT == ENABLED)
383 #if (FTP_SERVER_TLS_SUPPORT == ENABLED)
437 #if (FTP_SERVER_TLS_SUPPORT == ENABLED && TLS_TICKET_SUPPORT == ENABLED)
size_t responsePos
Current position in the response buffer.
@ FTP_CHANNEL_STATE_RECEIVE
OsTaskParameters taskParams
Task parameters.
uint_t(* FtpServerGetFilePermCallback)(FtpClientConnection *connection, const char_t *user, const char_t *path)
Callback used to retrieve file permissions.
error_t(* FtpServerUnknownCommandCallback)(FtpClientConnection *connection, const char_t *command, const char_t *param)
Unknown command callback function.
Socket * socket
Listening socket.
uint16_t passivePortMin
Passive port range (lower value)
OsTaskId taskId
Task identifier.
FtpServerConnectCallback connectCallback
Connection callback function.
FtpClientConnection * connections
Client connections.
FtpServerChannelState
Channel state.
#define FTP_SERVER_MAX_PATH_LEN
error_t ftpServerInit(FtpServerContext *context, const FtpServerSettings *settings)
FTP server initialization.
#define FTP_SERVER_MAX_USERNAME_LEN
FtpServerChannel controlChannel
Control channel.
void(* FtpServerDisconnectCallback)(FtpClientConnection *connection, const IpAddr *clientIpAddr, uint16_t clientPort)
Disconnection callback function.
@ FTP_SERVER_MODE_EXPLICIT_TLS
NetInterface * interface
Underlying network interface.
@ FTP_CHANNEL_STATE_SHUTDOWN_TLS
FtpServerContext * context
FTP server context.
void ftpServerTask(FtpServerContext *context)
FTP server task.
NetInterface * interface
Underlying network interface.
uint16_t dataPort
FTP data port number.
FtpAccessStatus
FTP server access status.
uint16_t remotePort
Remote port number.
char_t buffer[FTP_SERVER_BUFFER_SIZE]
Memory buffer for input/output operations.
#define FTP_SERVER_MAX_ROOT_DIR_LEN
uint32_t Ipv4Addr
IPv4 network address.
uint_t mode
Security modes.
Structure describing socket events.
uint16_t passivePortMax
Passive port range (upper value)
void ftpServerGetDefaultSettings(FtpServerSettings *settings)
Initialize settings with default values.
uint_t(* FtpServerCheckPasswordCallback)(FtpClientConnection *connection, const char_t *user, const char_t *password)
Password verification callback function.
@ FTP_CHANNEL_STATE_CLOSED
@ FTP_CHANNEL_STATE_AUTH_TLS_1
FtpServerMode
Security modes.
FtpServerChannelState state
Channel state.
OsTaskParameters task
Task parameters.
Session ticket encryption context.
IpAddr remoteIpAddr
Remote IP address.
char_t user[FTP_SERVER_MAX_USERNAME_LEN+1]
User name.
@ FTP_CHANNEL_STATE_WAIT_ACK
FtpServerCheckPasswordCallback checkPasswordCallback
Password verification callback function.
FtpServerSettings settings
User settings.
FtpServerGetFilePermCallback getFilePermCallback
Callback used to retrieve file permissions.
error_t ftpServerStart(FtpServerContext *context)
Start FTP server.
@ FTP_CHANNEL_STATE_LISTEN
Ipv4Addr publicIpv4Addr
Public IPv4 address to be used in PASV replies.
@ FTP_CHANNEL_STATE_AUTH_TLS_2
char_t command[FTP_SERVER_MAX_LINE_LEN+1]
Incoming command.
@ FTP_CHANNEL_STATE_SHUTDOWN_TX
bool_t userLoggedIn
This flag tells whether the user is logged in.
TlsContext * tlsContext
TLS context.
bool_t passiveMode
Passive data transfer.
char_t currentDir[FTP_SERVER_MAX_PATH_LEN+1]
Current directory.
General definitions for cryptographic algorithms.
@ FTP_CHANNEL_STATE_SHUTDOWN_RX
uint16_t port
FTP command port number.
#define FTP_SERVER_MAX_HOME_DIR_LEN
TlsTicketContext tlsTicketContext
TLS ticket encryption context.
OsEvent event
Event object used to poll the sockets.
#define FTP_SERVER_PRIVATE_CONTEXT
FsFile * file
File pointer.
#define FTP_SERVER_BUFFER_SIZE
File system abstraction layer.
error_t ftpServerSetHomeDir(FtpClientConnection *connection, const char_t *homeDir)
Set home directory.
@ FTP_CHANNEL_STATE_DISCARD
FtpServerTlsInitCallback tlsInitCallback
TLS initialization callback function.
uint32_t systime_t
System time.
SocketEventDesc eventDesc[2 *FTP_SERVER_MAX_CONNECTIONS+1]
The events the application is interested in.
size_t commandLen
Number of bytes available in the command buffer.
FsDir * dir
Directory pointer.
char_t path[FTP_SERVER_MAX_PATH_LEN+1]
Pathname.
FtpFilePerm
File permissions.
size_t responseLen
Number of bytes available in the response buffer.
error_t(* FtpServerTlsInitCallback)(FtpClientConnection *connection, TlsContext *tlsContext)
TLS initialization callback function.
FtpServerChannel dataChannel
Data channel.
error_t ftpServerStop(FtpServerContext *context)
Stop FTP server.
FtpClientConnection * connections
Client connections.
char_t homeDir[FTP_SERVER_MAX_HOME_DIR_LEN+1]
Home directory.
bool_t running
Operational state of the FTP server.
TLS (Transport Layer Security)
Socket * socket
Underlying TCP socket.
#define FTP_SERVER_MAX_LINE_LEN
FtpServerDisconnectCallback disconnectCallback
Disconnection callback function.
@ FTP_SERVER_MODE_PLAINTEXT
#define FtpClientConnection
uint16_t passivePort
Current passive port number.
FtpServerCheckUserCallback checkUserCallback
User verification callback function.
FtpServerUnknownCommandCallback unknownCommandCallback
Unknown command callback function.
#define FTP_SERVER_MAX_CONNECTIONS
size_t bufferPos
Current position in the buffer.
thread_t * OsTaskId
Task identifier.
uint_t maxConnections
Maximum number of client connections.
char_t response[FTP_SERVER_MAX_LINE_LEN+1]
Response buffer.
size_t bufferLength
Length of the buffer, in bytes.
uint_t(* FtpServerCheckUserCallback)(FtpClientConnection *connection, const char_t *user)
User verification callback function.
systime_t timestamp
Time stamp to manage timeout.
void ftpServerDeinit(FtpServerContext *context)
Release FTP server context.
error_t(* FtpServerConnectCallback)(FtpClientConnection *connection, const IpAddr *clientIpAddr, uint16_t clientPort)
Connection callback function.
@ FTP_CHANNEL_STATE_CONNECT_TLS
@ FTP_SERVER_MODE_IMPLICIT_TLS
void FsFile
File descriptor.