Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
FTP client library API

Data Structures

struct  ftp_client
 FTP client context. More...

Typedefs

typedef void(* ftp_client_callback_t) (const uint8_t *msg, uint16_t len)
 FTP asynchronous callback function.

Enumerations

enum  ftp_reply_code {
  FTP_CODE_110_RESTART_MARKER_REPLAY = 110 , FTP_CODE_120_SERVICE_READY_IN_NNN_MINUTES = 120 , FTP_CODE_125_DATA_CONN_ALREADY_OPEN = 125 , FTP_CODE_150_FILE_STATUS_OK = 150 ,
  FTP_CODE_200_OK = 200 , FTP_CODE_202_NOT_IMPLEMENTED = 202 , FTP_CODE_211_SYSTEM_STATUS = 211 , FTP_CODE_212_DIR_STATUS = 212 ,
  FTP_CODE_213_FILE_STATUS = 213 , FTP_CODE_214_HELP_MSG = 214 , FTP_CODE_215_NAME_SYSTEM_TYPE = 215 , FTP_CODE_220_SERVICE_READY = 220 ,
  FTP_CODE_221_SERVICE_CLOSING_CONN = 221 , FTP_CODE_225_DATA_CONN_OPEN = 225 , FTP_CODE_226_CLOSING_DATA_CONN_SUCCESS = 226 , FTP_CODE_227_ENTERING_PASSIVE_MODE = 227 ,
  FTP_CODE_228_ENTERING_LONG_PASSIVE_MODE = 228 , FTP_CODE_229_ENTERING_EXT_PASSIVE_MODE = 229 , FTP_CODE_230_USER_LOGGED_IN = 230 , FTP_CODE_231_USER_LOGGED_OUT = 231 ,
  FTP_CODE_233_LOGOUT_COMMAND_NOTED = 233 , FTP_CODE_234_SECURITY_ACCEPTED = 234 , FTP_CODE_250_FILE_ACTION_COMPLETED = 250 , FTP_CODE_257_PATHNAME_CREATED = 257 ,
  FTP_CODE_331_USERNAME_OK_NEED_PASSWORD = 331 , FTP_CODE_332_NEED_ACCOUNT = 332 , FTP_CODE_350_FILE_ACTION_PENDING = 350 , FTP_CODE_421_SERVICE_UNAVAILABLE = 421 ,
  FTP_CODE_425_CANNOT_OPEN_DATA_CONN = 425 , FTP_CODE_426_CONN_CLOSED = 426 , FTP_CODE_430_INVALID_USERNAME_OR_PASSWORD = 430 , FTP_CODE_434_HOST_UNAVAILABLE = 434 ,
  FTP_CODE_450_FILE_ACTION_NOT_TAKEN = 450 , FTP_CODE_451_ACTION_ABORTED = 451 , FTP_CODE_452_ACTION_NOT_TAKEN = 452 , FTP_CODE_500_GENERAL_ERROR = 500 ,
  FTP_CODE_501_SYNTAX_ERROR = 501 , FTP_CODE_502_COMMAND_NOT_COMPLETED = 502 , FTP_CODE_503_BAD_SEQUENCE_OF_COMMANDS = 503 , FTP_CODE_504_COMMAND_NOT_IMPLEMENTED = 504 ,
  FTP_CODE_530_NOT_LOGGED_IN = 530 , FTP_CODE_532_NEED_ACCOUNT = 532 , FTP_CODE_534_CANNOT_CONNECT_SSL_REQUIRED = 534 , FTP_CODE_550_FILE_UNAVAILABLE = 550 ,
  FTP_CODE_551_PAGE_TYPE_UNKNOWN = 551 , FTP_CODE_552_FILE_EXCEEDED_STORAGE_LOCATION = 552 , FTP_CODE_553_FILE_NAME_NOT_ALLOWED = 553 , FTP_CODE_631_INTEGRITY_PROTECTED_REPLY = 631 ,
  FTP_CODE_632_INT_AND_CONF_PROTECTED_REPLY = 632 , FTP_CODE_633_CONFIDENTIALITY_PROTECTED_REPLY = 633 , FTP_CODE_900_UNKNOWN_ERROR = 900 , FTP_CODE_901_DISCONNECTED_BY_REMOTE = 901 ,
  FTP_CODE_902_CONNECTION_ABORTED = 902 , FTP_CODE_903_SOCKET_POLL_ERROR = 903 , FTP_CODE_904_UNEXPECTED_POLL_EVENT = 904 , FTP_CODE_905_NETWORK_DOWN = 905 ,
  FTP_CODE_909_UNEXPECTED_ERROR = 909 , FTP_CODE_910_DATA_TRANSFER_TIMEOUT = 910 , FTP_CODE_10054_CONNECTION_RESET_BY_PEER = 10054 , FTP_CODE_10060_CANNOT_CONNECT = 10060 ,
  FTP_CODE_10061_CONNECTION_REFUSED = 10061 , FTP_CODE_10066_DIRECTORY_NOT_EMPTY = 10066 , FTP_CODE_10068_TOO_MANY_USERS = 10068
}
 List of FTP server reply codes Reference RFC959 FTP Transfer Protocol. More...
enum  ftp_transfer_type { FTP_TYPE_ASCII , FTP_TYPE_BINARY }
 FTP transfer mode. More...
enum  ftp_put_type { FTP_PUT_NORMAL , FTP_PUT_UNIQUE , FTP_PUT_APPEND }
 FTP file write mode. More...

Functions

int ftp_init (struct ftp_client *client, ftp_client_callback_t ctrl_callback, ftp_client_callback_t data_callback)
 Initialize the FTP client context.
int ftp_uninit (struct ftp_client *client)
 Uninitialize the FTP client context.
int ftp_open (struct ftp_client *client, const char *hostname, uint16_t port, int sec_tag)
 Open FTP connection.
int ftp_login (struct ftp_client *client, const char *username, const char *password)
 FTP server login.
int ftp_close (struct ftp_client *client)
 Close FTP connection.
int ftp_status (struct ftp_client *client)
 Get FTP server and connection status Also returns server system type.
int ftp_type (struct ftp_client *client, enum ftp_transfer_type type)
 Set FTP transfer type.
int ftp_pwd (struct ftp_client *client)
 Print working directory.
int ftp_list (struct ftp_client *client, const char *options, const char *target)
 List information of folder or file.
int ftp_cwd (struct ftp_client *client, const char *folder)
 Change working directory.
int ftp_mkd (struct ftp_client *client, const char *folder)
 Make directory.
int ftp_rmd (struct ftp_client *client, const char *folder)
 Remove directory.
int ftp_rename (struct ftp_client *client, const char *old_name, const char *new_name)
 Rename a file.
int ftp_delete (struct ftp_client *client, const char *file)
 Delete a file.
int ftp_get (struct ftp_client *client, const char *file)
 Get a file.
int ftp_put (struct ftp_client *client, const char *file, const uint8_t *data, uint16_t length, int type)
 Put data to a file If file does not exist, create the file.
int ftp_keepalive (struct ftp_client *client)
 Exchange keep-alive commands with the server.

Detailed Description

Since
4.4
Version
0.1.0

Typedef Documentation

◆ ftp_client_callback_t

typedef void(* ftp_client_callback_t) (const uint8_t *msg, uint16_t len)

#include <zephyr/net/ftp_client.h>

FTP asynchronous callback function.

Parameters
msgFTP client data received, or local message
lenlength of message

Enumeration Type Documentation

◆ ftp_put_type

#include <zephyr/net/ftp_client.h>

FTP file write mode.

Enumerator
FTP_PUT_NORMAL 

Overwrite a file.

FTP_PUT_UNIQUE 

Write to a file with a unique file name.

FTP_PUT_APPEND 

Append a file.

◆ ftp_reply_code

#include <zephyr/net/ftp_client.h>

List of FTP server reply codes Reference RFC959 FTP Transfer Protocol.

Enumerator
FTP_CODE_110_RESTART_MARKER_REPLAY 

Restart marker replay.

In this case, the text is exact and not left to the particular implementation; it must read: MARK yyyy = mmmm where yyyy is User-process data stream marker, and mmmm server's equivalent marker (note the spaces between markers and "=")

FTP_CODE_120_SERVICE_READY_IN_NNN_MINUTES 

Service ready in nnn minutes.

FTP_CODE_125_DATA_CONN_ALREADY_OPEN 

Data connection already open; transfer starting.

FTP_CODE_150_FILE_STATUS_OK 

File status okay; about to open data connection.

FTP_CODE_200_OK 

Command OK.

FTP_CODE_202_NOT_IMPLEMENTED 

Command not implemented, superfluous at this site.

FTP_CODE_211_SYSTEM_STATUS 

System status, or system help reply.

FTP_CODE_212_DIR_STATUS 

Directory status.

FTP_CODE_213_FILE_STATUS 

File status.

FTP_CODE_214_HELP_MSG 

Help message.

Explains how to use the server or the meaning of a particular non-standard command. This reply is useful only to the human user

FTP_CODE_215_NAME_SYSTEM_TYPE 

NAME system type.

Where NAME is an official system name from the registry kept by IANA.

FTP_CODE_220_SERVICE_READY 

Service ready for new user.

FTP_CODE_221_SERVICE_CLOSING_CONN 

Service closing control connection.

FTP_CODE_225_DATA_CONN_OPEN 

Data connection open; no transfer in progress.

FTP_CODE_226_CLOSING_DATA_CONN_SUCCESS 

Closing data connection.

Requested file action successful (for example, file transfer or file abort)

FTP_CODE_227_ENTERING_PASSIVE_MODE 

Entering Passive Mode (h1,h2,h3,h4,p1,p2).

FTP_CODE_228_ENTERING_LONG_PASSIVE_MODE 

Entering Long Passive Mode (long address, port).

FTP_CODE_229_ENTERING_EXT_PASSIVE_MODE 

Entering Extended Passive Mode (|||port|).

FTP_CODE_230_USER_LOGGED_IN 

User logged in, proceed.

Logged out if appropriate

FTP_CODE_231_USER_LOGGED_OUT 

User logged out; service terminated.

FTP_CODE_233_LOGOUT_COMMAND_NOTED 

Logout command noted, will complete when transfer done.

FTP_CODE_234_SECURITY_ACCEPTED 

Specifies that the server accepts the authentication mechanism specified by the client, and the exchange of security data is complete.

A higher level nonstandard code created by Microsoft

FTP_CODE_250_FILE_ACTION_COMPLETED 

Requested file action okay, completed.

FTP_CODE_257_PATHNAME_CREATED 

"PATHNAME" created

FTP_CODE_331_USERNAME_OK_NEED_PASSWORD 

User name okay, need password.

FTP_CODE_332_NEED_ACCOUNT 

Need account for login.

FTP_CODE_350_FILE_ACTION_PENDING 

Requested file action pending further information.

FTP_CODE_421_SERVICE_UNAVAILABLE 

Service not available, closing control connection.

This may be a reply to any command if the service knows it must shut down

FTP_CODE_425_CANNOT_OPEN_DATA_CONN 

Cannot open data connection.

FTP_CODE_426_CONN_CLOSED 

Connection closed; transfer aborted.

FTP_CODE_430_INVALID_USERNAME_OR_PASSWORD 

Invalid username or password.

FTP_CODE_434_HOST_UNAVAILABLE 

Requested host unavailable.

FTP_CODE_450_FILE_ACTION_NOT_TAKEN 

Requested file action not taken.

FTP_CODE_451_ACTION_ABORTED 

Requested action aborted.

Local error in processing

FTP_CODE_452_ACTION_NOT_TAKEN 

Requested action not taken.

Insufficient storage space in system. File unavailable (for example, file busy)

FTP_CODE_500_GENERAL_ERROR 

General error.

FTP_CODE_501_SYNTAX_ERROR 

Syntax error in parameters or arguments.

FTP_CODE_502_COMMAND_NOT_COMPLETED 

Command not implemented.

FTP_CODE_503_BAD_SEQUENCE_OF_COMMANDS 

Bad sequence of commands.

FTP_CODE_504_COMMAND_NOT_IMPLEMENTED 

Command not implemented for that parameter.

FTP_CODE_530_NOT_LOGGED_IN 

Not logged in.

FTP_CODE_532_NEED_ACCOUNT 

Need account for storing files.

FTP_CODE_534_CANNOT_CONNECT_SSL_REQUIRED 

Could Not Connect to Server - Policy Requires SSL.

FTP_CODE_550_FILE_UNAVAILABLE 

Requested action not taken.

File unavailable (for example, file not found, no access)

FTP_CODE_551_PAGE_TYPE_UNKNOWN 

Requested action aborted.

Page type unknown

FTP_CODE_552_FILE_EXCEEDED_STORAGE_LOCATION 

Requested file action aborted.

Exceeded storage allocation (for current directory or dataset)

FTP_CODE_553_FILE_NAME_NOT_ALLOWED 

Requested action not taken.

File name not allowed

FTP_CODE_631_INTEGRITY_PROTECTED_REPLY 

Integrity protected reply.

FTP_CODE_632_INT_AND_CONF_PROTECTED_REPLY 

Confidentiality and integrity protected reply.

FTP_CODE_633_CONFIDENTIALITY_PROTECTED_REPLY 

Confidentiality protected reply.

FTP_CODE_900_UNKNOWN_ERROR 

DUMMY.

FTP_CODE_901_DISCONNECTED_BY_REMOTE 

Fatal errors.

Disconnected by remote server

FTP_CODE_902_CONNECTION_ABORTED 

Connection aborted.

FTP_CODE_903_SOCKET_POLL_ERROR 

Socket poll error.

FTP_CODE_904_UNEXPECTED_POLL_EVENT 

Unexpected poll event.

FTP_CODE_905_NETWORK_DOWN 

Network down.

FTP_CODE_909_UNEXPECTED_ERROR 

Unexpected error.

FTP_CODE_910_DATA_TRANSFER_TIMEOUT 

Data transfer timeout.

FTP_CODE_10054_CONNECTION_RESET_BY_PEER 

Connection reset by peer.

The connection was forcibly closed by the remote host

FTP_CODE_10060_CANNOT_CONNECT 

Cannot connect to remote server.

FTP_CODE_10061_CONNECTION_REFUSED 

Cannot connect to remote server.

The connection is actively refused by the server

FTP_CODE_10066_DIRECTORY_NOT_EMPTY 

Directory not empty.

FTP_CODE_10068_TOO_MANY_USERS 

Too many users, server is full.

◆ ftp_transfer_type

#include <zephyr/net/ftp_client.h>

FTP transfer mode.

Enumerator
FTP_TYPE_ASCII 

ASCII transfer.

FTP_TYPE_BINARY 

Binary transfer.

Function Documentation

◆ ftp_close()

int ftp_close ( struct ftp_client * client)

#include <zephyr/net/ftp_client.h>

Close FTP connection.

Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_cwd()

int ftp_cwd ( struct ftp_client * client,
const char * folder )

#include <zephyr/net/ftp_client.h>

Change working directory.

Parameters
clientFTP client context
folderTarget folder
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_delete()

int ftp_delete ( struct ftp_client * client,
const char * file )

#include <zephyr/net/ftp_client.h>

Delete a file.

Parameters
clientFTP client context
fileTarget file name
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_get()

int ftp_get ( struct ftp_client * client,
const char * file )

#include <zephyr/net/ftp_client.h>

Get a file.

Parameters
clientFTP client context
fileTarget file name
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_init()

int ftp_init ( struct ftp_client * client,
ftp_client_callback_t ctrl_callback,
ftp_client_callback_t data_callback )

#include <zephyr/net/ftp_client.h>

Initialize the FTP client context.

Parameters
clientFTP client context
ctrl_callbackCallback for FTP command result.
data_callbackCallback for FTP received data.
Returns
0 on success. A negative errno code in case of a failure.

◆ ftp_keepalive()

int ftp_keepalive ( struct ftp_client * client)

#include <zephyr/net/ftp_client.h>

Exchange keep-alive commands with the server.

Parameters
clientFTP client context
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_list()

int ftp_list ( struct ftp_client * client,
const char * options,
const char * target )

#include <zephyr/net/ftp_client.h>

List information of folder or file.

Parameters
clientFTP client context
optionsList options, refer to Linux "man ls"
targetfile or directory to list. If not specified, list current folder
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_login()

int ftp_login ( struct ftp_client * client,
const char * username,
const char * password )

#include <zephyr/net/ftp_client.h>

FTP server login.

Parameters
clientFTP client context
usernameuser name
passwordThe password
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_mkd()

int ftp_mkd ( struct ftp_client * client,
const char * folder )

#include <zephyr/net/ftp_client.h>

Make directory.

Parameters
clientFTP client context
folderNew folder name
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_open()

int ftp_open ( struct ftp_client * client,
const char * hostname,
uint16_t port,
int sec_tag )

#include <zephyr/net/ftp_client.h>

Open FTP connection.

Parameters
clientFTP client context
hostnameFTP server name or IP address
portFTP service port on server
sec_tagIf FTP over TLS is required (-1 means no TLS)
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_put()

int ftp_put ( struct ftp_client * client,
const char * file,
const uint8_t * data,
uint16_t length,
int type )

#include <zephyr/net/ftp_client.h>

Put data to a file If file does not exist, create the file.

Parameters
clientFTP client context
fileTarget file name
dataData to be stored
lengthLength of data to be stored
typespecify FTP put types, see enum ftp_reply_code
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_pwd()

int ftp_pwd ( struct ftp_client * client)

#include <zephyr/net/ftp_client.h>

Print working directory.

Parameters
clientFTP client context
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_rename()

int ftp_rename ( struct ftp_client * client,
const char * old_name,
const char * new_name )

#include <zephyr/net/ftp_client.h>

Rename a file.

Parameters
clientFTP client context
old_nameOld file name
new_nameNew file name
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_rmd()

int ftp_rmd ( struct ftp_client * client,
const char * folder )

#include <zephyr/net/ftp_client.h>

Remove directory.

Parameters
clientFTP client context
folderTarget folder name
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_status()

int ftp_status ( struct ftp_client * client)

#include <zephyr/net/ftp_client.h>

Get FTP server and connection status Also returns server system type.

Parameters
clientFTP client context
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_type()

int ftp_type ( struct ftp_client * client,
enum ftp_transfer_type type )

#include <zephyr/net/ftp_client.h>

Set FTP transfer type.

Parameters
clientFTP client context
typetransfer type
Returns
0 on success. A negative errno code in case of a failure. A positive FTP status code in case of an unexpected server response.

◆ ftp_uninit()

int ftp_uninit ( struct ftp_client * client)

#include <zephyr/net/ftp_client.h>

Uninitialize the FTP client context.

Parameters
clientFTP client context
Returns
0 on success. A negative errno code in case of a failure.