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)
191 #include "core/crypto.h"
193 #include "tls_ticket.h"
199#define FTP_DATA_PORT 20
204#define FTPS_DATA_PORT 989
208#define FtpServerContext struct _FtpServerContext
212#define FtpClientConnection struct _FtpClientConnection
226 FTP_CHANNEL_STATE_CLOSED = 0,
227 FTP_CHANNEL_STATE_CONNECT_TLS = 1,
228 FTP_CHANNEL_STATE_LISTEN = 2,
229 FTP_CHANNEL_STATE_IDLE = 3,
230 FTP_CHANNEL_STATE_SEND = 4,
231 FTP_CHANNEL_STATE_RECEIVE = 5,
232 FTP_CHANNEL_STATE_DISCARD = 6,
233 FTP_CHANNEL_STATE_AUTH_TLS_1 = 7,
234 FTP_CHANNEL_STATE_AUTH_TLS_2 = 8,
235 FTP_CHANNEL_STATE_USER = 9,
236 FTP_CHANNEL_STATE_LIST = 10,
237 FTP_CHANNEL_STATE_NLST = 11,
238 FTP_CHANNEL_STATE_RETR = 12,
239 FTP_CHANNEL_STATE_STOR = 13,
240 FTP_CHANNEL_STATE_APPE = 14,
241 FTP_CHANNEL_STATE_RNFR = 15,
242 FTP_CHANNEL_STATE_SHUTDOWN_TLS = 16,
243 FTP_CHANNEL_STATE_WAIT_ACK = 17,
244 FTP_CHANNEL_STATE_SHUTDOWN_TX = 18,
245 FTP_CHANNEL_STATE_SHUTDOWN_RX = 19
255 FTP_SERVER_MODE_PLAINTEXT = 1,
256 FTP_SERVER_MODE_IMPLICIT_TLS = 2,
257 FTP_SERVER_MODE_EXPLICIT_TLS = 4
267 FTP_ACCESS_DENIED = 0,
268 FTP_ACCESS_ALLOWED = 1,
269 FTP_PASSWORD_REQUIRED = 2
279 FTP_FILE_PERM_LIST = 0x01,
280 FTP_FILE_PERM_READ = 0x02,
281 FTP_FILE_PERM_WRITE = 0x04
290 const IpAddr *clientIpAddr, uint16_t clientPort);
298 const IpAddr *clientIpAddr, uint16_t clientPort);
302#if (FTP_SERVER_TLS_SUPPORT == ENABLED)
309 TlsContext *tlsContext);
327 const char_t *
user,
const char_t *password);
335 const char_t *
user,
const char_t *
path);
343 const char_t *
command,
const char_t *param);
361 char_t rootDir[FTP_SERVER_MAX_ROOT_DIR_LEN + 1];
364#if (FTP_SERVER_TLS_SUPPORT == ENABLED)
382#if (FTP_SERVER_TLS_SUPPORT == ENABLED)
405 char_t
user[FTP_SERVER_MAX_USERNAME_LEN + 1];
406 char_t
homeDir[FTP_SERVER_MAX_HOME_DIR_LEN + 1];
408 char_t
path[FTP_SERVER_MAX_PATH_LEN + 1];
431#if (OS_STATIC_TASK_SUPPORT == ENABLED)
439#if (FTP_SERVER_TLS_SUPPORT == ENABLED && TLS_TICKET_SUPPORT == ENABLED)
442 FTP_SERVER_PRIVATE_CONTEXT
449error_t ftpServerInit(FtpServerContext *context,
452error_t ftpServerStart(FtpServerContext *context);
453error_t ftpServerStop(FtpServerContext *context);
455error_t ftpServerSetHomeDir(FtpClientConnection *connection,
456 const char_t *homeDir);
458void ftpServerTask(FtpServerContext *context);
460void ftpServerDeinit(FtpServerContext *context);
error_t
Error codes.
Definition error.h:43
File system abstraction layer.
void FsFile
File descriptor.
Definition fs_port_fatfs.h:60
error_t(* FtpServerUnknownCommandCallback)(FtpClientConnection *connection, const char_t *command, const char_t *param)
Unknown command callback function.
Definition ftp_server.h:342
error_t(* FtpServerConnectCallback)(FtpClientConnection *connection, const IpAddr *clientIpAddr, uint16_t clientPort)
Connection callback function.
Definition ftp_server.h:289
uint_t(* FtpServerGetFilePermCallback)(FtpClientConnection *connection, const char_t *user, const char_t *path)
Callback used to retrieve file permissions.
Definition ftp_server.h:334
FtpAccessStatus
FTP server access status.
Definition ftp_server.h:266
void(* FtpServerDisconnectCallback)(FtpClientConnection *connection, const IpAddr *clientIpAddr, uint16_t clientPort)
Disconnection callback function.
Definition ftp_server.h:297
FtpServerMode
Security modes.
Definition ftp_server.h:254
error_t(* FtpServerTlsInitCallback)(FtpClientConnection *connection, TlsContext *tlsContext)
TLS initialization callback function.
Definition ftp_server.h:308
FtpServerChannelState
Channel state.
Definition ftp_server.h:225
FtpFilePerm
File permissions.
Definition ftp_server.h:278
uint_t(* FtpServerCheckPasswordCallback)(FtpClientConnection *connection, const char_t *user, const char_t *password)
Password verification callback function.
Definition ftp_server.h:326
uint_t(* FtpServerCheckUserCallback)(FtpClientConnection *connection, const char_t *user)
User verification callback function.
Definition ftp_server.h:318
uint32_t Ipv4Addr
IPv4 network address.
Definition ipv4.h:267
uint_t OsEvent
Event object.
Definition os_port_none.h:104
uint_t OsTaskId
Task identifier.
Definition os_port_none.h:97
uint32_t systime_t
System time.
Definition os_port_none.h:90
Directory descriptor.
Definition fs_port_posix.h:60
Control or data channel.
Definition ftp_server.h:379
TlsContext * tlsContext
TLS context.
Definition ftp_server.h:383
Socket * socket
Underlying TCP socket.
Definition ftp_server.h:381
FtpServerChannelState state
Channel state.
Definition ftp_server.h:380
FTP server settings.
Definition ftp_server.h:351
uint16_t port
FTP command port number.
Definition ftp_server.h:353
uint_t mode
Security modes.
Definition ftp_server.h:358
FtpServerGetFilePermCallback getFilePermCallback
Callback used to retrieve file permissions.
Definition ftp_server.h:369
FtpServerConnectCallback connectCallback
Connection callback function.
Definition ftp_server.h:362
FtpServerDisconnectCallback disconnectCallback
Disconnection callback function.
Definition ftp_server.h:363
uint16_t passivePortMax
Passive port range (upper value)
Definition ftp_server.h:356
FtpServerCheckPasswordCallback checkPasswordCallback
Password verification callback function.
Definition ftp_server.h:368
uint16_t passivePortMin
Passive port range (lower value)
Definition ftp_server.h:355
FtpServerUnknownCommandCallback unknownCommandCallback
Unknown command callback function.
Definition ftp_server.h:370
FtpServerTlsInitCallback tlsInitCallback
TLS initialization callback function.
Definition ftp_server.h:365
FtpServerCheckUserCallback checkUserCallback
User verification callback function.
Definition ftp_server.h:367
Ipv4Addr publicIpv4Addr
Public IPv4 address to be used in PASV replies.
Definition ftp_server.h:357
FtpClientConnection * connections
Client connections.
Definition ftp_server.h:360
uint16_t dataPort
FTP data port number.
Definition ftp_server.h:354
uint_t maxConnections
Maximum number of client connections.
Definition ftp_server.h:359
NetInterface * interface
Underlying network interface.
Definition ftp_server.h:352
IP network address.
Definition ip.h:72
Structure describing socket events.
Definition socket.h:395
FTP client connection.
Definition ftp_server.h:393
char_t path[FTP_SERVER_MAX_PATH_LEN+1]
Pathname.
Definition ftp_server.h:408
bool_t passiveMode
Passive data transfer.
Definition ftp_server.h:402
NetInterface * interface
Underlying network interface.
Definition ftp_server.h:395
FtpServerChannel controlChannel
Control channel.
Definition ftp_server.h:398
FtpServerContext * context
FTP server context.
Definition ftp_server.h:394
char_t homeDir[FTP_SERVER_MAX_HOME_DIR_LEN+1]
Home directory.
Definition ftp_server.h:406
char_t command[FTP_SERVER_MAX_LINE_LEN+1]
Incoming command.
Definition ftp_server.h:409
size_t commandLen
Number of bytes available in the command buffer.
Definition ftp_server.h:410
FsDir * dir
Directory pointer.
Definition ftp_server.h:401
bool_t userLoggedIn
This flag tells whether the user is logged in.
Definition ftp_server.h:396
char_t user[FTP_SERVER_MAX_USERNAME_LEN+1]
User name.
Definition ftp_server.h:405
FtpServerChannel dataChannel
Data channel.
Definition ftp_server.h:399
IpAddr remoteIpAddr
Remote IP address.
Definition ftp_server.h:403
char_t currentDir[FTP_SERVER_MAX_PATH_LEN+1]
Current directory.
Definition ftp_server.h:407
systime_t timestamp
Time stamp to manage timeout.
Definition ftp_server.h:397
size_t responsePos
Current position in the response buffer.
Definition ftp_server.h:413
char_t buffer[FTP_SERVER_BUFFER_SIZE]
Memory buffer for input/output operations.
Definition ftp_server.h:414
char_t response[FTP_SERVER_MAX_LINE_LEN+1]
Response buffer.
Definition ftp_server.h:411
size_t responseLen
Number of bytes available in the response buffer.
Definition ftp_server.h:412
uint16_t remotePort
Remote port number.
Definition ftp_server.h:404
size_t bufferLength
Length of the buffer, in bytes.
Definition ftp_server.h:415
size_t bufferPos
Current position in the buffer.
Definition ftp_server.h:416
FsFile * file
File pointer.
Definition ftp_server.h:400
FTP server context.
Definition ftp_server.h:425
bool_t stop
Stop request.
Definition ftp_server.h:428
Socket * socket
Listening socket.
Definition ftp_server.h:435
OsStackType taskStack[FTP_SERVER_STACK_SIZE]
Task stack.
Definition ftp_server.h:433
OsTaskTcb taskTcb
Task control block.
Definition ftp_server.h:432
FtpServerSettings settings
User settings.
Definition ftp_server.h:426
bool_t running
Operational state of the FTP server.
Definition ftp_server.h:427
OsTaskId taskId
Task identifier.
Definition ftp_server.h:430
FtpClientConnection * connections
Client connections.
Definition ftp_server.h:437
SocketEventDesc eventDesc[2 *FTP_SERVER_MAX_CONNECTIONS+1]
The events the application is interested in.
Definition ftp_server.h:438
OsEvent event
Event object used to poll the sockets.
Definition ftp_server.h:429
TlsTicketContext tlsTicketContext
TLS ticket encryption context.
Definition ftp_server.h:440
uint16_t passivePort
Current passive port number.
Definition ftp_server.h:436