Trivial File Transfer Protocol (TFTP) Client#
The TFTP Client facilitates file exchange between a client and any remote host over UDP. This component provides an easy-to-use solution for downloading and uploading files from a remote host. The TFTP client can be initialized with sl_tftp_clnt_init(), and the functions sl_tftp_clnt_get() and sl_tftp_clnt_put() can be used to download and upload files, respectively. Additionally, the block size and timeout options can be configured to negotiate between the server and the client, optimizing the transmission. The component implements the TFTP protocol as specified in RFC 1350.
To ensure proper functionality, a TFTP server, such as tftpd-hpa, must be prepared on the remote host.
The following code example shows how to download a file with TFTP Client:
#include "sl_tftp_clnt.h"
// TFTP data callback
// In this callback you can implement storing data chunks to flash, heap or any other memory.
static void tftp_data_hnd(sl_tftp_clnt_t * const clnt,
const uint8_t * const data_ptr,
const uint16_t data_size) {
(void)data_ptr;
(void)data_size;
printf("Data received chunk %u (%u bytes)\n",
clnt->packet.content.data.block_num,
clnt->packet.content.data.data_size);
}
// TFTP error callback
// You can implement error handling in this callback.
static void tftp_error_hnd(sl_tftp_clnt_t * const clnt,
const uint16_t error_code,
const char *error_msg) {
(void)clnt;
printf("Error (%u): %s\n", error_code, error_msg);
}
static void tftp_get_file(void) {
static sl_tftp_clnt_t tftp_clnt = { 0 };
// Initialize Client instance
if (sl_tftp_clnt_init(&tftp_clnt,
"2001:db8::1",
SL_TFTP_DEFAULT_HOST_PORT,
tftp_data_hnd,
tftp_error_hnd) != SL_STATUS_OK) {
// Error handling
return;
}
// Set blocksize option
if (sl_tftp_clnt_set_option(&tftp_clnt,
SL_TFTP_OPT_EXT_BLOCKSIZE,
1228) != SL_STATUS_OK) {
// Error handling
return;
}
// Start to download a file
if (sl_tftp_clnt_get(&tftp_clnt,
"test.txt") != SL_STATUS_OK) {
// Error handling
return;
}
while (1) {
if (sl_tftp_clnt_is_op_finished(&tftp_clnt)) {
printf("File download finished\n");
break;
}
osDelay(1);
}
}
Modules#
Typedefs#
Data handler callback definition.
Error handler callback defintion.
Functions#
Init TFTP Client default.
TFT Client Get.
Init TFTP Client.
TFTP Client is finished operation.
TFTP Client is Get operation.
TFTP Client is Put operation.
TFTP Client is RRQ or WRQ failed.
Print packet.
TFT Client Put.
TFTP Client request.
Init TFTP Client service.
Set TFTP Client option.
TFTP Client terminate session.
Macros#
TFTP Default data block size.
Default TFTP host port.
TFTP Default server retransmit timeout interval in seconds.
Access violation.
Disk full or allocation exceeded.
File already exists.
File not found.
Illegal TFTP operation.
Not defined, see error message (if any).
No such user.
Terminate transfer due to option negotiation.
Unknown transfer ID.
Netascii mode string.
Netascii mode string length.
Octet mode string.
Octet mode string length.
TFTP Acknowledgement operation code.
TFTP Data operation code.
TFTP Error operation code.
TFTP Option Acknowledgement operation code.
TFTP Read Request operation code.
TFTP Write Request operation code.
TFTP Blocksize Option.
TFTP Blocksize Option length.
TFTP Multicast Option.
TFTP Multicast Option length.
TFTP Timeout Interval Option.
TFTP Timeout Interval Option length.
TFTP Transfer Size Option.
TFTP Transfer Size Option length.
TFTP Windowsize Option.
TFTP Windowsize Option length.
TFTP receive timeout.
TFTP Service loop definition.
TFTP string max length (filename, mode)
Typedef Documentation#
sl_tftp_clnt_data_hnd_t#
typedef void(* sl_tftp_clnt_data_hnd_t) (sl_tftp_clnt_t *const clnt, const uint8_t *const data_ptr, const uint16_t data_size) )(sl_tftp_clnt_t *const clnt, const uint8_t *const data_ptr, const uint16_t data_size)
Data handler callback definition.
247
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_error_hnd_t#
typedef void(* sl_tftp_clnt_error_hnd_t) (sl_tftp_clnt_t *const clnt, const uint16_t error_code, const char *error_msg) )(sl_tftp_clnt_t *const clnt, const uint16_t error_code, const char *error_msg)
Error handler callback defintion.
252
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
Function Documentation#
sl_tftp_clnt_default_init#
__STATIC_INLINE sl_status_t sl_tftp_clnt_default_init (sl_tftp_clnt_t *const clnt)
Init TFTP Client default.
[inout] | clnt | Client to initialize |
Initialize Client with default values from config file parameters: host: SL_TFTP_CLNT_DEFAULT_HOST port: SL_TFTP_DEFAULT_HOST_PORT data_hnd: simple hex dump callback error_hnd: error code and message printer Returns
sl_status_t SL_STATUS_OK on success, otherwise SL_STATUS_FAIL
292
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_get#
__STATIC_INLINE sl_status_t sl_tftp_clnt_get (sl_tftp_clnt_t *const clnt, const char * file)
TFT Client Get.
[inout] | clnt | Client |
[in] | file | File name |
Get file from server in octet mode Returns
sl_status_t SL_STATUS_OK on success, otherwise SL_STATUS_FAIL
342
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_init#
sl_status_t sl_tftp_clnt_init (sl_tftp_clnt_t *const clnt, const char * host, const uint16_t port, sl_tftp_clnt_data_hnd_t data_hnd, sl_tftp_clnt_error_hnd_t error_hnd)
Init TFTP Client.
[inout] | clnt | Client to initialize |
[in] | host | Host address string |
[in] | port | Port number |
[in] | data_hnd | Data handler callback |
[in] | error_hnd | Error handler callback |
Initialize TFTP Client context Returns
sl_status_t SL_STATUS_OK on success, otherwise SL_STATUS_FAIL
276
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_is_op_finished#
bool sl_tftp_clnt_is_op_finished (const sl_tftp_clnt_t *const clnt)
TFTP Client is finished operation.
[in] | clnt | Client |
Check read or write operations wheither is in progress Returns
true Is finished
false Is in progress
376
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_is_op_get#
bool sl_tftp_clnt_is_op_get (const sl_tftp_clnt_t *const clnt)
TFTP Client is Get operation.
[in] | clnt | Client |
Check Read operation is in progress Returns
true Is in progress otherwise false
384
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_is_op_put#
bool sl_tftp_clnt_is_op_put (const sl_tftp_clnt_t *const clnt)
TFTP Client is Put operation.
[in] | clnt | Client |
Check Write operation is in progress Returns
true Is in progress otherwise false
392
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_is_op_rrq_wrq_failed#
bool sl_tftp_clnt_is_op_rrq_wrq_failed (const sl_tftp_clnt_t *const clnt)
TFTP Client is RRQ or WRQ failed.
[in] | clnt | Client |
Check Read or Write Request operation is failed Returns
true Is failed otherwise false
400
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_print_pkt#
void sl_tftp_clnt_print_pkt (const sl_tftp_pkt_t *const pkt)
Print packet.
[in] | pkt | Packet to print |
Print packet info in json format
304
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_put#
__STATIC_INLINE sl_status_t sl_tftp_clnt_put (sl_tftp_clnt_t *const clnt, const char * file)
TFT Client Put.
[inout] | clnt | Client |
[in] | file | File name to store data |
Send buffer content to file on remote server Returns
sl_status_t SL_STATUS_OK on success, otherwise SL_STATUS_FAIL
363
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_request#
sl_status_t sl_tftp_clnt_request (sl_tftp_clnt_t *const clnt, const uint16_t opcode, const char * file, const char * mode)
TFTP Client request.
[inout] | clnt | Client |
[in] | opcode | Operation code: SL_TFTP_OPCODE_RRQ or SL_TFTP_OPCODE_WRQ |
[in] | file | File name to put or get |
[in] | mode | Mode string |
Send request for Server (RRQ or WRQ) Returns
sl_status_t SL_STATUS_OK on success, otherwise SL_STATUS_FAIL
330
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_service_init#
void sl_tftp_clnt_service_init (void )
Init TFTP Client service.
N/A |
Initialize TFTP client OS objects
264
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_set_option#
sl_status_t sl_tftp_clnt_set_option (sl_tftp_clnt_t *const clnt, const char * opt, const uint32_t value)
Set TFTP Client option.
[inout] | clnt | Client |
[in] | opt | Option string |
[in] | value | Option value |
Set TFTP Client option in the TFTP client instance. The supported options are:
SL_TFTP_OPT_EXT_BLOCKSIZE: Blocksize option (8 - 1228 for Wi-SUN)
SL_TFTP_OPT_EXT_TIMEOUT_INTERVAL: Timeout interval option (1 - 255) Returns
sl_status_t SL_STATUS_OK on success, otherwise SL_STATUS_FAIL
317
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
sl_tftp_clnt_terminate_session#
sl_status_t sl_tftp_clnt_terminate_session (sl_tftp_clnt_t *const clnt)
TFTP Client terminate session.
[inout] | clnt | Client |
Terminate TFTP session Returns
sl_status_t SL_STATUS_OK on success, otherwise SL_STATUS_FAIL
354
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
Macro Definition Documentation#
SL_TFTP_DEFAULT_DATA_BLOCK_SIZE#
#define SL_TFTP_DEFAULT_DATA_BLOCK_SIZEValue:
512U
TFTP Default data block size.
63
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_DEFAULT_HOST_PORT#
#define SL_TFTP_DEFAULT_HOST_PORTValue:
69U
Default TFTP host port.
60
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_DEFAULT_SRV_RET_TIMEOUT_SEC#
#define SL_TFTP_DEFAULT_SRV_RET_TIMEOUT_SECValue:
1U
TFTP Default server retransmit timeout interval in seconds.
66
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_ERROCODE_ACCVIOL#
#define SL_TFTP_ERROCODE_ACCVIOLValue:
2U
Access violation.
122
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_ERROCODE_DISKFULL#
#define SL_TFTP_ERROCODE_DISKFULLValue:
3U
Disk full or allocation exceeded.
124
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_ERROCODE_FEXIST#
#define SL_TFTP_ERROCODE_FEXISTValue:
6U
File already exists.
130
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_ERROCODE_FNOTFOUND#
#define SL_TFTP_ERROCODE_FNOTFOUNDValue:
1U
File not found.
120
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_ERROCODE_ILLEGALOP#
#define SL_TFTP_ERROCODE_ILLEGALOPValue:
4U
Illegal TFTP operation.
126
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_ERROCODE_NOTDEF#
#define SL_TFTP_ERROCODE_NOTDEFValue:
0U
Not defined, see error message (if any).
118
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_ERROCODE_NOUSR#
#define SL_TFTP_ERROCODE_NOUSRValue:
7U
No such user.
132
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_ERROCODE_OPTNEGOTFAIL#
#define SL_TFTP_ERROCODE_OPTNEGOTFAILValue:
8U
Terminate transfer due to option negotiation.
134
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_ERROCODE_UNKNTID#
#define SL_TFTP_ERROCODE_UNKNTIDValue:
5U
Unknown transfer ID.
128
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_MODE_NETASCII_STR#
#define SL_TFTP_MODE_NETASCII_STRValue:
"netascii"
Netascii mode string.
75
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_MODE_NETASCII_STR_LEN#
#define SL_TFTP_MODE_NETASCII_STR_LENValue:
8U
Netascii mode string length.
79
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_MODE_OCTET_STR#
#define SL_TFTP_MODE_OCTET_STRValue:
"octet"
Octet mode string.
77
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_MODE_OCTET_STR_LEN#
#define SL_TFTP_MODE_OCTET_STR_LENValue:
5U
Octet mode string length.
81
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPCODE_ACK#
#define SL_TFTP_OPCODE_ACKValue:
4U
TFTP Acknowledgement operation code.
111
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPCODE_DATA#
#define SL_TFTP_OPCODE_DATAValue:
3U
TFTP Data operation code.
109
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPCODE_ERROR#
#define SL_TFTP_OPCODE_ERRORValue:
5U
TFTP Error operation code.
113
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPCODE_OACK#
#define SL_TFTP_OPCODE_OACKValue:
6U
TFTP Option Acknowledgement operation code.
115
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPCODE_RRQ#
#define SL_TFTP_OPCODE_RRQValue:
1U
TFTP Read Request operation code.
105
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPCODE_WRQ#
#define SL_TFTP_OPCODE_WRQValue:
2U
TFTP Write Request operation code.
107
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPT_EXT_BLOCKSIZE#
#define SL_TFTP_OPT_EXT_BLOCKSIZEValue:
"blksize"
TFTP Blocksize Option.
84
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPT_EXT_BLOCKSIZE_LEN#
#define SL_TFTP_OPT_EXT_BLOCKSIZE_LENValue:
7U
TFTP Blocksize Option length.
86
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPT_EXT_MULTICAST#
#define SL_TFTP_OPT_EXT_MULTICASTValue:
"multicast"
TFTP Multicast Option.
88
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPT_EXT_MULTICAST_LEN#
#define SL_TFTP_OPT_EXT_MULTICAST_LENValue:
9U
TFTP Multicast Option length.
90
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPT_EXT_TIMEOUT_INTERVAL#
#define SL_TFTP_OPT_EXT_TIMEOUT_INTERVALValue:
"timeout"
TFTP Timeout Interval Option.
92
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPT_EXT_TIMEOUT_INTERVAL_LEN#
#define SL_TFTP_OPT_EXT_TIMEOUT_INTERVAL_LENValue:
7U
TFTP Timeout Interval Option length.
94
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPT_EXT_TRANSFER_SIZE#
#define SL_TFTP_OPT_EXT_TRANSFER_SIZEValue:
"tsize"
TFTP Transfer Size Option.
96
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPT_EXT_TRANSFER_SIZE_LEN#
#define SL_TFTP_OPT_EXT_TRANSFER_SIZE_LENValue:
5U
TFTP Transfer Size Option length.
98
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPT_EXT_WINDOWSIZE#
#define SL_TFTP_OPT_EXT_WINDOWSIZEValue:
"windowsize"
TFTP Windowsize Option.
100
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_OPT_EXT_WINDOWSIZE_LEN#
#define SL_TFTP_OPT_EXT_WINDOWSIZE_LENValue:
10U
TFTP Windowsize Option length.
102
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_RECV_TIMEOUT_MS#
#define SL_TFTP_RECV_TIMEOUT_MSValue:
8000UL
TFTP receive timeout.
69
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_SERVICE_LOOP#
#define SL_TFTP_SERVICE_LOOPValue:
while (1)
TFTP Service loop definition.
138
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h
SL_TFTP_STR_MAX_LEN#
#define SL_TFTP_STR_MAX_LENValue:
256UL
TFTP string max length (filename, mode)
72
of file /mnt/raid/workspaces/ws.obQFDUprC/overlay/gsdk/app/wisun/component/ftp/sl_tftp_clnt.h