ftp_server.h File Reference

FTP server (File Transfer Protocol) More...

#include "core/net.h"
#include "core/socket.h"
#include "fs_port.h"
#include "core/crypto.h"
#include "tls.h"
#include "tls_ticket.h"

Go to the source code of this file.

Data Structures

struct  FtpServerSettings
 FTP server settings. More...
 
struct  FtpServerChannel
 Control or data channel. More...
 
struct  _FtpClientConnection
 FTP client connection. More...
 
struct  _FtpServerContext
 FTP server context. More...
 

Macros

#define FTP_SERVER_SUPPORT   ENABLED
 
#define FTP_SERVER_TLS_SUPPORT   DISABLED
 
#define FTP_SERVER_STACK_SIZE   650
 
#define FTP_SERVER_PRIORITY   OS_TASK_PRIORITY_NORMAL
 
#define FTP_SERVER_MAX_CONNECTIONS   10
 
#define FTP_SERVER_TIMEOUT   60000
 
#define FTP_SERVER_TICK_INTERVAL   1000
 
#define FTP_SERVER_BACKLOG   4
 
#define FTP_SERVER_MAX_LINE_LEN   255
 
#define FTP_SERVER_BUFFER_SIZE   1024
 
#define FTP_SERVER_MAX_ROOT_DIR_LEN   63
 
#define FTP_SERVER_MAX_HOME_DIR_LEN   63
 
#define FTP_SERVER_MAX_USERNAME_LEN   63
 
#define FTP_SERVER_MAX_PATH_LEN   255
 
#define FTP_SERVER_MIN_TCP_BUFFER_SIZE   1430
 
#define FTP_SERVER_MAX_TCP_BUFFER_SIZE   2860
 
#define FTP_SERVER_TLS_TX_BUFFER_SIZE   4096
 
#define FTP_SERVER_MIN_TLS_RX_BUFFER_SIZE   2048
 
#define FTP_SERVER_MAX_TLS_RX_BUFFER_SIZE   16384
 
#define FTP_SERVER_PASSIVE_PORT_MIN   48128
 
#define FTP_SERVER_PASSIVE_PORT_MAX   49151
 
#define FTP_SERVER_PRIVATE_CONTEXT
 
#define FTP_PORT   21
 
#define FTP_DATA_PORT   20
 
#define FTPS_PORT   990
 
#define FTPS_DATA_PORT   989
 
#define FtpServerContext   struct _FtpServerContext
 
#define FtpClientConnection   struct _FtpClientConnection
 

Typedefs

typedef error_t(* FtpServerConnectCallback) (FtpClientConnection *connection, const IpAddr *clientIpAddr, uint16_t clientPort)
 Connection callback function. More...
 
typedef void(* FtpServerDisconnectCallback) (FtpClientConnection *connection, const IpAddr *clientIpAddr, uint16_t clientPort)
 Disconnection callback function. More...
 
typedef error_t(* FtpServerTlsInitCallback) (FtpClientConnection *connection, TlsContext *tlsContext)
 TLS initialization callback function. More...
 
typedef uint_t(* FtpServerCheckUserCallback) (FtpClientConnection *connection, const char_t *user)
 User verification callback function. More...
 
typedef uint_t(* FtpServerCheckPasswordCallback) (FtpClientConnection *connection, const char_t *user, const char_t *password)
 Password verification callback function. More...
 
typedef uint_t(* FtpServerGetFilePermCallback) (FtpClientConnection *connection, const char_t *user, const char_t *path)
 Callback used to retrieve file permissions. More...
 
typedef error_t(* FtpServerUnknownCommandCallback) (FtpClientConnection *connection, const char_t *command, const char_t *param)
 Unknown command callback function. More...
 

Enumerations

enum  FtpServerChannelState {
  FTP_CHANNEL_STATE_CLOSED = 0, FTP_CHANNEL_STATE_CONNECT_TLS = 1, FTP_CHANNEL_STATE_LISTEN = 2, FTP_CHANNEL_STATE_IDLE = 3,
  FTP_CHANNEL_STATE_SEND = 4, FTP_CHANNEL_STATE_RECEIVE = 5, FTP_CHANNEL_STATE_DISCARD = 6, FTP_CHANNEL_STATE_AUTH_TLS_1 = 7,
  FTP_CHANNEL_STATE_AUTH_TLS_2 = 8, FTP_CHANNEL_STATE_USER = 9, FTP_CHANNEL_STATE_LIST = 10, FTP_CHANNEL_STATE_NLST = 11,
  FTP_CHANNEL_STATE_RETR = 12, FTP_CHANNEL_STATE_STOR = 13, FTP_CHANNEL_STATE_APPE = 14, FTP_CHANNEL_STATE_RNFR = 15,
  FTP_CHANNEL_STATE_SHUTDOWN_TLS = 16, FTP_CHANNEL_STATE_WAIT_ACK = 17, FTP_CHANNEL_STATE_SHUTDOWN_TX = 18, FTP_CHANNEL_STATE_SHUTDOWN_RX = 19
}
 Channel state. More...
 
enum  FtpServerMode { FTP_SERVER_MODE_PLAINTEXT = 1, FTP_SERVER_MODE_IMPLICIT_TLS = 2, FTP_SERVER_MODE_EXPLICIT_TLS = 4 }
 Security modes. More...
 
enum  FtpAccessStatus { FTP_ACCESS_DENIED = 0, FTP_ACCESS_ALLOWED = 1, FTP_PASSWORD_REQUIRED = 2 }
 FTP server access status. More...
 
enum  FtpFilePerm { FTP_FILE_PERM_LIST = 0x01, FTP_FILE_PERM_READ = 0x02, FTP_FILE_PERM_WRITE = 0x04 }
 File permissions. More...
 

Functions

void ftpServerGetDefaultSettings (FtpServerSettings *settings)
 Initialize settings with default values. More...
 
error_t ftpServerInit (FtpServerContext *context, const FtpServerSettings *settings)
 FTP server initialization. More...
 
error_t ftpServerStart (FtpServerContext *context)
 Start FTP server. More...
 
error_t ftpServerStop (FtpServerContext *context)
 Stop FTP server. More...
 
error_t ftpServerSetHomeDir (FtpClientConnection *connection, const char_t *homeDir)
 Set home directory. More...
 
void ftpServerTask (FtpServerContext *context)
 FTP server task. More...
 
void ftpServerDeinit (FtpServerContext *context)
 Release FTP server context. More...
 

Detailed Description

FTP server (File Transfer Protocol)

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file ftp_server.h.

Macro Definition Documentation

◆ FTP_DATA_PORT

#define FTP_DATA_PORT   20

Definition at line 199 of file ftp_server.h.

◆ FTP_PORT

#define FTP_PORT   21

Definition at line 197 of file ftp_server.h.

◆ FTP_SERVER_BACKLOG

#define FTP_SERVER_BACKLOG   4

Definition at line 88 of file ftp_server.h.

◆ FTP_SERVER_BUFFER_SIZE

#define FTP_SERVER_BUFFER_SIZE   1024

Definition at line 102 of file ftp_server.h.

◆ FTP_SERVER_MAX_CONNECTIONS

#define FTP_SERVER_MAX_CONNECTIONS   10

Definition at line 67 of file ftp_server.h.

◆ FTP_SERVER_MAX_HOME_DIR_LEN

#define FTP_SERVER_MAX_HOME_DIR_LEN   63

Definition at line 116 of file ftp_server.h.

◆ FTP_SERVER_MAX_LINE_LEN

#define FTP_SERVER_MAX_LINE_LEN   255

Definition at line 95 of file ftp_server.h.

◆ FTP_SERVER_MAX_PATH_LEN

#define FTP_SERVER_MAX_PATH_LEN   255

Definition at line 130 of file ftp_server.h.

◆ FTP_SERVER_MAX_ROOT_DIR_LEN

#define FTP_SERVER_MAX_ROOT_DIR_LEN   63

Definition at line 109 of file ftp_server.h.

◆ FTP_SERVER_MAX_TCP_BUFFER_SIZE

#define FTP_SERVER_MAX_TCP_BUFFER_SIZE   2860

Definition at line 144 of file ftp_server.h.

◆ FTP_SERVER_MAX_TLS_RX_BUFFER_SIZE

#define FTP_SERVER_MAX_TLS_RX_BUFFER_SIZE   16384

Definition at line 165 of file ftp_server.h.

◆ FTP_SERVER_MAX_USERNAME_LEN

#define FTP_SERVER_MAX_USERNAME_LEN   63

Definition at line 123 of file ftp_server.h.

◆ FTP_SERVER_MIN_TCP_BUFFER_SIZE

#define FTP_SERVER_MIN_TCP_BUFFER_SIZE   1430

Definition at line 137 of file ftp_server.h.

◆ FTP_SERVER_MIN_TLS_RX_BUFFER_SIZE

#define FTP_SERVER_MIN_TLS_RX_BUFFER_SIZE   2048

Definition at line 158 of file ftp_server.h.

◆ FTP_SERVER_PASSIVE_PORT_MAX

#define FTP_SERVER_PASSIVE_PORT_MAX   49151

Definition at line 179 of file ftp_server.h.

◆ FTP_SERVER_PASSIVE_PORT_MIN

#define FTP_SERVER_PASSIVE_PORT_MIN   48128

Definition at line 172 of file ftp_server.h.

◆ FTP_SERVER_PRIORITY

#define FTP_SERVER_PRIORITY   OS_TASK_PRIORITY_NORMAL

Definition at line 62 of file ftp_server.h.

◆ FTP_SERVER_PRIVATE_CONTEXT

#define FTP_SERVER_PRIVATE_CONTEXT

Definition at line 186 of file ftp_server.h.

◆ FTP_SERVER_STACK_SIZE

#define FTP_SERVER_STACK_SIZE   650

Definition at line 55 of file ftp_server.h.

◆ FTP_SERVER_SUPPORT

#define FTP_SERVER_SUPPORT   ENABLED

Definition at line 41 of file ftp_server.h.

◆ FTP_SERVER_TICK_INTERVAL

#define FTP_SERVER_TICK_INTERVAL   1000

Definition at line 81 of file ftp_server.h.

◆ FTP_SERVER_TIMEOUT

#define FTP_SERVER_TIMEOUT   60000

Definition at line 74 of file ftp_server.h.

◆ FTP_SERVER_TLS_SUPPORT

#define FTP_SERVER_TLS_SUPPORT   DISABLED

Definition at line 48 of file ftp_server.h.

◆ FTP_SERVER_TLS_TX_BUFFER_SIZE

#define FTP_SERVER_TLS_TX_BUFFER_SIZE   4096

Definition at line 151 of file ftp_server.h.

◆ FtpClientConnection

#define FtpClientConnection   struct _FtpClientConnection

Definition at line 212 of file ftp_server.h.

◆ FTPS_DATA_PORT

#define FTPS_DATA_PORT   989

Definition at line 204 of file ftp_server.h.

◆ FTPS_PORT

#define FTPS_PORT   990

Definition at line 202 of file ftp_server.h.

◆ FtpServerContext

#define FtpServerContext   struct _FtpServerContext

Definition at line 208 of file ftp_server.h.

Typedef Documentation

◆ FtpServerCheckPasswordCallback

typedef uint_t(* FtpServerCheckPasswordCallback) (FtpClientConnection *connection, const char_t *user, const char_t *password)

Password verification callback function.

Definition at line 326 of file ftp_server.h.

◆ FtpServerCheckUserCallback

typedef uint_t(* FtpServerCheckUserCallback) (FtpClientConnection *connection, const char_t *user)

User verification callback function.

Definition at line 318 of file ftp_server.h.

◆ FtpServerConnectCallback

typedef error_t(* FtpServerConnectCallback) (FtpClientConnection *connection, const IpAddr *clientIpAddr, uint16_t clientPort)

Connection callback function.

Definition at line 289 of file ftp_server.h.

◆ FtpServerDisconnectCallback

typedef void(* FtpServerDisconnectCallback) (FtpClientConnection *connection, const IpAddr *clientIpAddr, uint16_t clientPort)

Disconnection callback function.

Definition at line 297 of file ftp_server.h.

◆ FtpServerGetFilePermCallback

typedef uint_t(* FtpServerGetFilePermCallback) (FtpClientConnection *connection, const char_t *user, const char_t *path)

Callback used to retrieve file permissions.

Definition at line 334 of file ftp_server.h.

◆ FtpServerTlsInitCallback

typedef error_t(* FtpServerTlsInitCallback) (FtpClientConnection *connection, TlsContext *tlsContext)

TLS initialization callback function.

Definition at line 308 of file ftp_server.h.

◆ FtpServerUnknownCommandCallback

typedef error_t(* FtpServerUnknownCommandCallback) (FtpClientConnection *connection, const char_t *command, const char_t *param)

Unknown command callback function.

Definition at line 342 of file ftp_server.h.

Enumeration Type Documentation

◆ FtpAccessStatus

FTP server access status.

Enumerator
FTP_ACCESS_DENIED 
FTP_ACCESS_ALLOWED 
FTP_PASSWORD_REQUIRED 

Definition at line 265 of file ftp_server.h.

◆ FtpFilePerm

File permissions.

Enumerator
FTP_FILE_PERM_LIST 
FTP_FILE_PERM_READ 
FTP_FILE_PERM_WRITE 

Definition at line 277 of file ftp_server.h.

◆ FtpServerChannelState

Channel state.

Enumerator
FTP_CHANNEL_STATE_CLOSED 
FTP_CHANNEL_STATE_CONNECT_TLS 
FTP_CHANNEL_STATE_LISTEN 
FTP_CHANNEL_STATE_IDLE 
FTP_CHANNEL_STATE_SEND 
FTP_CHANNEL_STATE_RECEIVE 
FTP_CHANNEL_STATE_DISCARD 
FTP_CHANNEL_STATE_AUTH_TLS_1 
FTP_CHANNEL_STATE_AUTH_TLS_2 
FTP_CHANNEL_STATE_USER 
FTP_CHANNEL_STATE_LIST 
FTP_CHANNEL_STATE_NLST 
FTP_CHANNEL_STATE_RETR 
FTP_CHANNEL_STATE_STOR 
FTP_CHANNEL_STATE_APPE 
FTP_CHANNEL_STATE_RNFR 
FTP_CHANNEL_STATE_SHUTDOWN_TLS 
FTP_CHANNEL_STATE_WAIT_ACK 
FTP_CHANNEL_STATE_SHUTDOWN_TX 
FTP_CHANNEL_STATE_SHUTDOWN_RX 

Definition at line 224 of file ftp_server.h.

◆ FtpServerMode

Security modes.

Enumerator
FTP_SERVER_MODE_PLAINTEXT 
FTP_SERVER_MODE_IMPLICIT_TLS 
FTP_SERVER_MODE_EXPLICIT_TLS 

Definition at line 253 of file ftp_server.h.

Function Documentation

◆ ftpServerDeinit()

void ftpServerDeinit ( FtpServerContext context)

Release FTP server context.

Parameters
[in]contextPointer to the FTP server context

Definition at line 541 of file ftp_server.c.

◆ ftpServerGetDefaultSettings()

void ftpServerGetDefaultSettings ( FtpServerSettings settings)

Initialize settings with default values.

Parameters
[out]settingsStructure that contains FTP server settings

Definition at line 60 of file ftp_server.c.

◆ ftpServerInit()

error_t ftpServerInit ( FtpServerContext context,
const FtpServerSettings settings 
)

FTP server initialization.

Parameters
[in]contextPointer to the FTP server context
[in]settingsFTP server specific settings
Returns
Error code

Definition at line 120 of file ftp_server.c.

◆ ftpServerSetHomeDir()

error_t ftpServerSetHomeDir ( FtpClientConnection connection,
const char_t homeDir 
)

Set home directory.

Parameters
[in]connectionPointer to the client connection
[in]homeDirNULL-terminated string specifying the home directory
Returns
Error code

Definition at line 370 of file ftp_server.c.

◆ ftpServerStart()

error_t ftpServerStart ( FtpServerContext context)

Start FTP server.

Parameters
[in]contextPointer to the FTP server context
Returns
Error code

Definition at line 210 of file ftp_server.c.

◆ ftpServerStop()

error_t ftpServerStop ( FtpServerContext context)

Stop FTP server.

Parameters
[in]contextPointer to the FTP server context
Returns
Error code

Definition at line 319 of file ftp_server.c.

◆ ftpServerTask()

void ftpServerTask ( FtpServerContext context)

FTP server task.

Parameters
[in]contextPointer to the FTP server context

Definition at line 397 of file ftp_server.c.