Network Component
Version 6.6
MDK-Professional Middleware for IP Networking
|
FTP Client Routines provide access to a FTP Server. More...
Functions | |
netStatus | ftp_client_connect (const uint8_t *ip_addr, uint16_t port, ftpCommand command) |
Start FTP client file operation session. | |
void | ftp_client_fclose (void *file) |
Close local file previously open in FTP client. | |
void * | ftp_client_fopen (const char *fname, const char *mode) |
Open local file for reading or writing in FTP client. | |
uint32_t | ftp_client_fread (void *file, uint8_t *buf, uint32_t len) |
Read block of data from local file in FTP client. | |
uint32_t | ftp_client_fwrite (void *file, const uint8_t *buf, uint32_t len) |
Write block of data to local file in FTP client. | |
void | ftp_client_notify (ftpClientEvent event) |
Notify the user application when FTP client operation ends. | |
uint32_t | ftp_client_request (ftpClientRequest request, char *buf, uint32_t len) |
Request parameters for FTP client session. | |
enum | ftpClientRequest { ftpClientUsername, ftpClientPassword, ftpClientPath, ftpClientFilename, ftpClientNewName, ftpClientDirectory, ftpClientFilterMask, ftpClientList, ftpClientLocalFile } |
FTP Client Requests. More... | |
enum | ftpClientEvent { ftpClientSuccess = 0, ftpClientTimeout, ftpClientLoginFailed, ftpClientAccessDenied, ftpClientFileNotFound, ftpClientInvalidPath, ftpClientLocalFileError, ftpClientError } |
FTP Client Events. More... | |
FTP Client Routines provide access to a FTP Server.
FTP routines are not reentrant.
enum ftpClientEvent |
FTP Client Events.
Parameter for:
enum ftpClientRequest |
FTP Client Requests.
Parameter for:
netStatus ftp_client_connect | ( | const uint8_t * | ip_addr, |
uint16_t | port, | ||
ftpCommand | command | ||
) |
Start FTP client file operation session.
[in] | ip_addr | IP address of remote FTP server. |
[in] | port | port number of FTP server. |
[in] | command | FTP command to perform. |
The function ftp_client_connect starts the FTP client. The FTP client then connects to a FTP server on the TCP port. If the port is not specified (argument port has a value of 0), then the system uses a standard FTP server port for connecting.
The argument ip_addr points to an array of 4 bytes containing the dotted-decimal notation of the IP address of the FTP server.
The argument port is the FTP server port to connect to.
The argument command specifies a command that is preformed when the FTP client connects to the FTP server. The following commands are supported:
Command | Description |
---|---|
ftpPUT | Puts a local file from local system to FTP server |
ftpGET | Retrieves a file from FTP server to save as a local file |
ftpAPPEND | Appends a local file to an existing file on FTP server |
ftpDELETE | Deletes a file from FTP server |
ftpLIST | Lists files located on FTP server (including detailed information) |
ftpRENAME | Renames a file or directory on FTP server |
ftpMKDIR | Creates a new directory on FTP server |
ftpRMDIR | Deletes an empty directory on FTP server |
ftpNLIST | Lists file names located on FTP server (names only) |
Code Example
void ftp_client_fclose | ( | void * | file | ) |
Close local file previously open in FTP client.
[in] | file | pointer to the file to close. |
The function ftp_client_fclose closes the file identified by the file stream pointer.
The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the FTP_Client_FS.c module.
void * ftp_client_fopen | ( | const char * | fname, |
const char * | mode | ||
) |
Open local file for reading or writing in FTP client.
[in] | fname | name of the file to open. |
[in] | mode | type of access:
|
The function ftp_client_fopen opens a local file for reading or writing.
The argument mode defines the type of access permitted for the file fname. mode can have one of the following values:
Mode | Description |
---|---|
"rb" | Opens the file for reading. If the file does not exist, fopen fails. |
"wb" | Opens an empty file for writing. If the file already exists, its contents are cleared. |
The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the FTP_Client_FS.c module.
uint32_t ftp_client_fread | ( | void * | file, |
uint8_t * | buf, | ||
uint32_t | len | ||
) |
Read block of data from local file in FTP client.
[in] | file | pointer to the file to read from. |
[out] | buf | block of memory to write data to. |
[in] | len | length of data to read in bytes. |
The function ftp_client_fread reads len bytes from the file identified by the file stream pointer in the function argument.
The argument buf is a pointer to the buffer where the function stores the data read.
The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the FTP_Client_FS.c module.
uint32_t ftp_client_fwrite | ( | void * | file, |
const uint8_t * | buf, | ||
uint32_t | len | ||
) |
Write block of data to local file in FTP client.
[in] | file | pointer to the file to write to. |
[in] | buf | block of memory to be written. |
[in] | len | length of data to write in bytes. |
The function ftp_client_fwrite writes a block of data to the file identified by the file stream pointer.
The argument buf points to the buffer containing the data that is to be written to the file.
The argument len specifies the number of bytes to write to the file.
The function interfaces to the File System Component and will be called by the Network Component automatically. If another file system will be used, refer to the reference implementation in the FTP_Client_FS.c module.
void ftp_client_notify | ( | ftpClientEvent | event | ) |
Notify the user application when FTP client operation ends.
[in] | event | FTP client notification event |
The function ftp_client_notify is called automatically when an FTP event occurred and notifies the user application when the FTP client operation ends.
The argument event is a ftpClientEvent signal:
Event | Description |
---|---|
ftpClientSuccess | The file operation completed successfully |
ftpClientTimeout | FTP Server response has timed out, and hence the FTP client has aborted the operation |
ftpClientLoginFailed | The FTP client failed to login to FTP server |
ftpClientAccessDenied | The file access to a specified file is not allowed |
ftpClientFileNotFound | The requested file was not found on FTP server |
ftpClientInvalidPath | Working directory path not found on FTP server |
ftpClientLocalFileError | File open or file write error on local system |
ftpClientError | An error encountered during the file operation |
You can customize the function in FTP_Client_UIF.c module.
Code Example
uint32_t ftp_client_request | ( | ftpClientRequest | request, |
char * | buf, | ||
uint32_t | len | ||
) |
Request parameters for FTP client session.
[in] | request | request code. |
[out] | buf | output buffer to write the data to. |
[in] | len | length of the output buffer in bytes. |
The function ftp_client_request provides additional parameters for the FTP client session such as the credentials to login to the FTP server, local and remote file name for the file operation, etc. The FTP client calls this function several times to complete the file operation requested.
The argument request specifies the type of additional information (user, password, file name, etc.) that the FTP Client requires:
Type | Description |
---|---|
ftpClientUsername | Username for FTP authentication |
ftpClientPassword | Password for FTP authentication |
ftpClientDirectory | Working directory path for all commands |
ftpClientFilename | Filename for PUT, GET, APPEND, DELETE or RENAME commands |
ftpClientNewName | New filename for RENAME command |
ftpClientPath | A directory name for MKDIR or RMDIR command |
ftpClientFilterMask | A file filter/mask for the LIST command |
ftpClientList | Received directory listing when the LIST command was given |
The argument buf is a pointer to the output buffer where the function writes the requested data.
The argument buflen specifies the length of the output buffer in bytes.
The function is in the FTP_Client_UIF.c module.
Code Example