ftp_client.h File Reference

FTP client (File Transfer Protocol) More...

#include "core/net.h"
#include "date_time.h"
#include "core/crypto.h"
#include "tls.h"

Go to the source code of this file.

Data Structures

struct  FtpClientSocket
 Control or data connection. More...
 
struct  _FtpClientContext
 FTP client context. More...
 
struct  FtpDirEntry
 Directory entry. More...
 

Macros

#define FTP_CLIENT_SUPPORT   ENABLED
 
#define FTP_CLIENT_TLS_SUPPORT   DISABLED
 
#define FTP_CLIENT_DEFAULT_TIMEOUT   20000
 
#define FTP_CLIENT_BUFFER_SIZE   512
 
#define FTP_CLIENT_MIN_TCP_BUFFER_SIZE   1430
 
#define FTP_CLIENT_MAX_TCP_BUFFER_SIZE   2860
 
#define FTP_CLIENT_TLS_TX_BUFFER_SIZE   2048
 
#define FTP_CLIENT_MIN_TLS_RX_BUFFER_SIZE   4096
 
#define FTP_CLIENT_MAX_TLS_RX_BUFFER_SIZE   16384
 
#define FTP_CLIENT_MAX_FILENAME_LEN   64
 
#define FTP_REPLY_CODE_1YZ(code)   ((code) >= 100 && (code) < 200)
 
#define FTP_REPLY_CODE_2YZ(code)   ((code) >= 200 && (code) < 300)
 
#define FTP_REPLY_CODE_3YZ(code)   ((code) >= 300 && (code) < 400)
 
#define FTP_REPLY_CODE_4YZ(code)   ((code) >= 400 && (code) < 500)
 
#define FTP_REPLY_CODE_5YZ(code)   ((code) >= 500 && (code) < 600)
 
#define FtpClientContext   struct _FtpClientContext
 

Typedefs

typedef error_t(* FtpClientTlsInitCallback) (FtpClientContext *context, TlsContext *tlsContext)
 TLS initialization callback function. More...
 

Enumerations

enum  FtpConnectionModes {
  FTP_MODE_PLAINTEXT = 0, FTP_MODE_IMPLICIT_TLS = 1, FTP_MODE_EXPLICIT_TLS = 2, FTP_MODE_ACTIVE = 0,
  FTP_MODE_PASSIVE = 4
}
 FTP connection modes. More...
 
enum  FtpFileModes {
  FTP_FILE_MODE_READ = 0, FTP_FILE_MODE_WRITE = 1, FTP_FILE_MODE_APPEND = 2, FTP_FILE_MODE_BINARY = 0,
  FTP_FILE_MODE_TEXT = 4
}
 File access modes. More...
 
enum  FtpFileFlags {
  FTP_FLAG_PEEK = 0x0200, FTP_FLAG_WAIT_ALL = 0x0800, FTP_FLAG_BREAK_CHAR = 0x1000, FTP_FLAG_BREAK_CRLF = 0x100A,
  FTP_FLAG_WAIT_ACK = 0x2000
}
 Flags used by I/O functions. More...
 
enum  FtpFileAttributes { FTP_FILE_ATTR_DIRECTORY = 1, FTP_FILE_ATTR_READ_ONLY = 2 }
 File attributes. More...
 
enum  FtpClientState {
  FTP_CLIENT_STATE_DISCONNECTED = 0, FTP_CLIENT_STATE_ACCEPTING_TCP = 1, FTP_CLIENT_STATE_CONNECTING_TCP = 2, FTP_CLIENT_STATE_CONNECTING_TLS = 3,
  FTP_CLIENT_STATE_CONNECTED = 4, FTP_CLIENT_STATE_SUB_COMMAND_1 = 5, FTP_CLIENT_STATE_SUB_COMMAND_2 = 6, FTP_CLIENT_STATE_SUB_COMMAND_3 = 7,
  FTP_CLIENT_STATE_SUB_COMMAND_4 = 8, FTP_CLIENT_STATE_SUB_COMMAND_5 = 9, FTP_CLIENT_STATE_SUB_COMMAND_6 = 10, FTP_CLIENT_STATE_SUB_COMMAND_7 = 11,
  FTP_CLIENT_STATE_SUB_COMMAND_8 = 12, FTP_CLIENT_STATE_SUB_COMMAND_9 = 13, FTP_CLIENT_STATE_WRITING_DATA = 14, FTP_CLIENT_STATE_READING_DATA = 15,
  FTP_CLIENT_STATE_DISCONNECTING_1 = 16, FTP_CLIENT_STATE_DISCONNECTING_2 = 17
}
 FTP client states. More...
 

Functions

error_t ftpClientInit (FtpClientContext *context)
 Initialize FTP client context. More...
 
error_t ftpClientRegisterTlsInitCallback (FtpClientContext *context, FtpClientTlsInitCallback callback)
 Register TLS initialization callback function. More...
 
error_t ftpClientSetTimeout (FtpClientContext *context, systime_t timeout)
 Set communication timeout. More...
 
error_t ftpClientBindToInterface (FtpClientContext *context, NetInterface *interface)
 Bind the FTP client to a particular network interface. More...
 
error_t ftpClientConnect (FtpClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort, uint_t mode)
 Establish a connection with the specified FTP server. More...
 
error_t ftpClientLogin (FtpClientContext *context, const char_t *username, const char_t *password)
 Login to the FTP server using the provided user name and password. More...
 
error_t ftpClientLoginEx (FtpClientContext *context, const char_t *username, const char_t *password, const char_t *account)
 Login to the FTP server using user name, password and account. More...
 
error_t ftpClientGetWorkingDir (FtpClientContext *context, char_t *path, size_t maxLen)
 Get current working directory. More...
 
error_t ftpClientChangeWorkingDir (FtpClientContext *context, const char_t *path)
 Change working directory. More...
 
error_t ftpClientChangeToParentDir (FtpClientContext *context)
 Change to parent directory. More...
 
error_t ftpClientOpenDir (FtpClientContext *context, const char_t *path)
 Open a directory. More...
 
error_t ftpClientReadDir (FtpClientContext *context, FtpDirEntry *dirEntry)
 Read an entry from the directory. More...
 
error_t ftpClientCloseDir (FtpClientContext *context)
 Close directory. More...
 
error_t ftpClientMakeDir (FtpClientContext *context, const char_t *path)
 Create a new directory. More...
 
error_t ftpClientRemoveDir (FtpClientContext *context, const char_t *path)
 Remove a directory on the FTP server. More...
 
error_t ftpClientOpenFile (FtpClientContext *context, const char_t *path, uint_t mode)
 Open a file for reading, writing, or appending. More...
 
error_t ftpClientWriteFile (FtpClientContext *context, const void *data, size_t length, size_t *written, uint_t flags)
 Write to a remote file. More...
 
error_t ftpClientReadFile (FtpClientContext *context, void *data, size_t size, size_t *length, uint_t flags)
 Read from a remote file. More...
 
error_t ftpClientCloseFile (FtpClientContext *context)
 Close file. More...
 
error_t ftpClientRenameFile (FtpClientContext *context, const char_t *oldName, const char_t *newName)
 Rename a remote file. More...
 
error_t ftpClientDeleteFile (FtpClientContext *context, const char_t *path)
 Delete a file. More...
 
uint_t ftpClientGetReplyCode (FtpClientContext *context)
 Retrieve server's reply code. More...
 
error_t ftpClientDisconnect (FtpClientContext *context)
 Gracefully disconnect from the FTP server. More...
 
error_t ftpClientClose (FtpClientContext *context)
 Close the connection with the FTP server. More...
 
void ftpClientDeinit (FtpClientContext *context)
 Release FTP client context. More...
 
error_t ftpConnect (FtpClientContext *context, NetInterface *interface, const IpAddr *serverIpAddr, uint16_t serverPort, uint_t flags)
 

Detailed Description

FTP client (File Transfer Protocol)

License

Copyright (C) 2010-2018 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
1.9.0

Definition in file ftp_client.h.

Macro Definition Documentation

◆ FTP_CLIENT_BUFFER_SIZE

#define FTP_CLIENT_BUFFER_SIZE   512

Definition at line 59 of file ftp_client.h.

◆ FTP_CLIENT_DEFAULT_TIMEOUT

#define FTP_CLIENT_DEFAULT_TIMEOUT   20000

Definition at line 52 of file ftp_client.h.

◆ FTP_CLIENT_MAX_FILENAME_LEN

#define FTP_CLIENT_MAX_FILENAME_LEN   64

Definition at line 101 of file ftp_client.h.

◆ FTP_CLIENT_MAX_TCP_BUFFER_SIZE

#define FTP_CLIENT_MAX_TCP_BUFFER_SIZE   2860

Definition at line 73 of file ftp_client.h.

◆ FTP_CLIENT_MAX_TLS_RX_BUFFER_SIZE

#define FTP_CLIENT_MAX_TLS_RX_BUFFER_SIZE   16384

Definition at line 94 of file ftp_client.h.

◆ FTP_CLIENT_MIN_TCP_BUFFER_SIZE

#define FTP_CLIENT_MIN_TCP_BUFFER_SIZE   1430

Definition at line 66 of file ftp_client.h.

◆ FTP_CLIENT_MIN_TLS_RX_BUFFER_SIZE

#define FTP_CLIENT_MIN_TLS_RX_BUFFER_SIZE   4096

Definition at line 87 of file ftp_client.h.

◆ FTP_CLIENT_SUPPORT

#define FTP_CLIENT_SUPPORT   ENABLED

Definition at line 38 of file ftp_client.h.

◆ FTP_CLIENT_TLS_SUPPORT

#define FTP_CLIENT_TLS_SUPPORT   DISABLED

Definition at line 45 of file ftp_client.h.

◆ FTP_CLIENT_TLS_TX_BUFFER_SIZE

#define FTP_CLIENT_TLS_TX_BUFFER_SIZE   2048

Definition at line 80 of file ftp_client.h.

◆ FTP_REPLY_CODE_1YZ

#define FTP_REPLY_CODE_1YZ (   code)    ((code) >= 100 && (code) < 200)

Definition at line 113 of file ftp_client.h.

◆ FTP_REPLY_CODE_2YZ

#define FTP_REPLY_CODE_2YZ (   code)    ((code) >= 200 && (code) < 300)

Definition at line 114 of file ftp_client.h.

◆ FTP_REPLY_CODE_3YZ

#define FTP_REPLY_CODE_3YZ (   code)    ((code) >= 300 && (code) < 400)

Definition at line 115 of file ftp_client.h.

◆ FTP_REPLY_CODE_4YZ

#define FTP_REPLY_CODE_4YZ (   code)    ((code) >= 400 && (code) < 500)

Definition at line 116 of file ftp_client.h.

◆ FTP_REPLY_CODE_5YZ

#define FTP_REPLY_CODE_5YZ (   code)    ((code) >= 500 && (code) < 600)

Definition at line 117 of file ftp_client.h.

◆ FtpClientContext

#define FtpClientContext   struct _FtpClientContext

Definition at line 121 of file ftp_client.h.

Typedef Documentation

◆ FtpClientTlsInitCallback

typedef error_t(* FtpClientTlsInitCallback) (FtpClientContext *context, TlsContext *tlsContext)

TLS initialization callback function.

Definition at line 216 of file ftp_client.h.

Enumeration Type Documentation

◆ FtpClientState

FTP client states.

Enumerator
FTP_CLIENT_STATE_DISCONNECTED 
FTP_CLIENT_STATE_ACCEPTING_TCP 
FTP_CLIENT_STATE_CONNECTING_TCP 
FTP_CLIENT_STATE_CONNECTING_TLS 
FTP_CLIENT_STATE_CONNECTED 
FTP_CLIENT_STATE_SUB_COMMAND_1 
FTP_CLIENT_STATE_SUB_COMMAND_2 
FTP_CLIENT_STATE_SUB_COMMAND_3 
FTP_CLIENT_STATE_SUB_COMMAND_4 
FTP_CLIENT_STATE_SUB_COMMAND_5 
FTP_CLIENT_STATE_SUB_COMMAND_6 
FTP_CLIENT_STATE_SUB_COMMAND_7 
FTP_CLIENT_STATE_SUB_COMMAND_8 
FTP_CLIENT_STATE_SUB_COMMAND_9 
FTP_CLIENT_STATE_WRITING_DATA 
FTP_CLIENT_STATE_READING_DATA 
FTP_CLIENT_STATE_DISCONNECTING_1 
FTP_CLIENT_STATE_DISCONNECTING_2 

Definition at line 186 of file ftp_client.h.

◆ FtpConnectionModes

FTP connection modes.

Enumerator
FTP_MODE_PLAINTEXT 
FTP_MODE_IMPLICIT_TLS 
FTP_MODE_EXPLICIT_TLS 
FTP_MODE_ACTIVE 
FTP_MODE_PASSIVE 

Definition at line 133 of file ftp_client.h.

◆ FtpFileAttributes

File attributes.

Enumerator
FTP_FILE_ATTR_DIRECTORY 
FTP_FILE_ATTR_READ_ONLY 

Definition at line 175 of file ftp_client.h.

◆ FtpFileFlags

Flags used by I/O functions.

Enumerator
FTP_FLAG_PEEK 
FTP_FLAG_WAIT_ALL 
FTP_FLAG_BREAK_CHAR 
FTP_FLAG_BREAK_CRLF 
FTP_FLAG_WAIT_ACK 

Definition at line 161 of file ftp_client.h.

◆ FtpFileModes

File access modes.

Enumerator
FTP_FILE_MODE_READ 
FTP_FILE_MODE_WRITE 
FTP_FILE_MODE_APPEND 
FTP_FILE_MODE_BINARY 
FTP_FILE_MODE_TEXT 

Definition at line 147 of file ftp_client.h.

Function Documentation

◆ ftpClientBindToInterface()

error_t ftpClientBindToInterface ( FtpClientContext context,
NetInterface interface 
)

Bind the FTP client to a particular network interface.

Parameters
[in]contextPointer to the FTP client context
[in]interfaceNetwork interface to be used
Returns
Error code

Definition at line 146 of file ftp_client.c.

◆ ftpClientChangeToParentDir()

error_t ftpClientChangeToParentDir ( FtpClientContext context)

Change to parent directory.

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

Definition at line 696 of file ftp_client.c.

◆ ftpClientChangeWorkingDir()

error_t ftpClientChangeWorkingDir ( FtpClientContext context,
const char_t path 
)

Change working directory.

Parameters
[in]contextPointer to the FTP client context
[in]pathThe new current working directory
Returns
Error code

Definition at line 622 of file ftp_client.c.

◆ ftpClientClose()

error_t ftpClientClose ( FtpClientContext context)

Close the connection with the FTP server.

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

Definition at line 1719 of file ftp_client.c.

◆ ftpClientCloseDir()

error_t ftpClientCloseDir ( FtpClientContext context)

Close directory.

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

Definition at line 991 of file ftp_client.c.

◆ ftpClientCloseFile()

error_t ftpClientCloseFile ( FtpClientContext context)

Close file.

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

Definition at line 1406 of file ftp_client.c.

◆ ftpClientConnect()

error_t ftpClientConnect ( FtpClientContext context,
const IpAddr serverIpAddr,
uint16_t  serverPort,
uint_t  mode 
)

Establish a connection with the specified FTP server.

Parameters
[in]contextPointer to the FTP client context
[in]serverIpAddrIP address of the FTP server
[in]serverPortPort number
[in]modeFTP connection mode
Returns
Error code

Definition at line 170 of file ftp_client.c.

◆ ftpClientDeinit()

void ftpClientDeinit ( FtpClientContext context)

Release FTP client context.

Parameters
[in]contextPointer to the FTP client context

Definition at line 1742 of file ftp_client.c.

◆ ftpClientDeleteFile()

error_t ftpClientDeleteFile ( FtpClientContext context,
const char_t path 
)

Delete a file.

Parameters
[in]contextPointer to the FTP client context
[in]pathPath to the file to be be deleted
Returns
Error code

Definition at line 1530 of file ftp_client.c.

◆ ftpClientDisconnect()

error_t ftpClientDisconnect ( FtpClientContext context)

Gracefully disconnect from the FTP server.

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

Definition at line 1630 of file ftp_client.c.

◆ ftpClientGetReplyCode()

uint_t ftpClientGetReplyCode ( FtpClientContext context)

Retrieve server's reply code.

Parameters
[in]contextPointer to the FTP client context
Returns
FTP reply code

Definition at line 1603 of file ftp_client.c.

◆ ftpClientGetWorkingDir()

error_t ftpClientGetWorkingDir ( FtpClientContext context,
char_t path,
size_t  maxLen 
)

Get current working directory.

Parameters
[in]contextPointer to the FTP client context
[out]pathOutput buffer where to store the current directory
[in]maxLenMaximum number of characters the buffer can hold
Returns
Error code

Definition at line 542 of file ftp_client.c.

◆ ftpClientInit()

error_t ftpClientInit ( FtpClientContext context)

Initialize FTP client context.

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

Definition at line 60 of file ftp_client.c.

◆ ftpClientLogin()

error_t ftpClientLogin ( FtpClientContext context,
const char_t username,
const char_t password 
)

Login to the FTP server using the provided user name and password.

Parameters
[in]contextPointer to the FTP client context
[in]usernameNULL-terminated string containing the user name
[in]passwordNULL-terminated string containing the user's password
Returns
Error code

Definition at line 375 of file ftp_client.c.

◆ ftpClientLoginEx()

error_t ftpClientLoginEx ( FtpClientContext context,
const char_t username,
const char_t password,
const char_t account 
)

Login to the FTP server using user name, password and account.

Parameters
[in]contextPointer to the FTP client context
[in]usernameNULL-terminated string containing the user name
[in]passwordNULL-terminated string containing the user's password
[in]accountNULL-terminated string containing the user's account
Returns
Error code

Definition at line 392 of file ftp_client.c.

◆ ftpClientMakeDir()

error_t ftpClientMakeDir ( FtpClientContext context,
const char_t path 
)

Create a new directory.

Parameters
[in]contextPointer to the FTP client context
[in]pathThe name of the new directory
Returns
Error code

Definition at line 1009 of file ftp_client.c.

◆ ftpClientOpenDir()

error_t ftpClientOpenDir ( FtpClientContext context,
const char_t path 
)

Open a directory.

Parameters
[in]contextPointer to the FTP client context
[in]pathPath to the directory to be be opened
Returns
Directory handle

Definition at line 770 of file ftp_client.c.

◆ ftpClientOpenFile()

error_t ftpClientOpenFile ( FtpClientContext context,
const char_t path,
uint_t  mode 
)

Open a file for reading, writing, or appending.

Parameters
[in]contextPointer to the FTP client context
[in]pathPath to the file to be be opened
[in]modeFile access mode
Returns
Error code

Definition at line 1158 of file ftp_client.c.

◆ ftpClientReadDir()

error_t ftpClientReadDir ( FtpClientContext context,
FtpDirEntry dirEntry 
)

Read an entry from the directory.

Parameters
[in]contextPointer to the FTP client context
[out]dirEntryPointer to a directory entry
Returns
Error code

Definition at line 896 of file ftp_client.c.

◆ ftpClientReadFile()

error_t ftpClientReadFile ( FtpClientContext context,
void *  data,
size_t  size,
size_t *  length,
uint_t  flags 
)

Read from a remote file.

Parameters
[in]contextPointer to the FTP client context
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be read
[out]lengthActual number of bytes that have been read
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1357 of file ftp_client.c.

◆ ftpClientRegisterTlsInitCallback()

error_t ftpClientRegisterTlsInitCallback ( FtpClientContext context,
FtpClientTlsInitCallback  callback 
)

Register TLS initialization callback function.

Parameters
[in]contextPointer to the FTP client context
[in]callbackTLS initialization callback function
Returns
Error code

Definition at line 101 of file ftp_client.c.

◆ ftpClientRemoveDir()

error_t ftpClientRemoveDir ( FtpClientContext context,
const char_t path 
)

Remove a directory on the FTP server.

Parameters
[in]contextPointer to the FTP client context
[in]pathPath to the directory to be removed
Returns
Error code

Definition at line 1083 of file ftp_client.c.

◆ ftpClientRenameFile()

error_t ftpClientRenameFile ( FtpClientContext context,
const char_t oldName,
const char_t newName 
)

Rename a remote file.

Parameters
[in]contextPointer to the FTP client context
[in]oldNameThe name of the remote file to rename
[in]newNameThe new name of the remote file
Returns
Error code

Definition at line 1425 of file ftp_client.c.

◆ ftpClientSetTimeout()

error_t ftpClientSetTimeout ( FtpClientContext context,
systime_t  timeout 
)

Set communication timeout.

Parameters
[in]contextPointer to the FTP client context
[in]timeoutTimeout value, in milliseconds
Returns
Error code

Definition at line 125 of file ftp_client.c.

◆ ftpClientWriteFile()

error_t ftpClientWriteFile ( FtpClientContext context,
const void *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Write to a remote file.

Parameters
[in]contextPointer to the FTP client context
[in]dataPointer to a buffer containing the data to be written
[in]lengthNumber of data bytes to write
[in]writtenNumber of bytes that have been written
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1304 of file ftp_client.c.

◆ ftpConnect()

error_t ftpConnect ( FtpClientContext context,
NetInterface interface,
const IpAddr serverIpAddr,
uint16_t  serverPort,
uint_t  flags 
)

Definition at line 1763 of file ftp_client.c.