Network Component
Version 6.6
MDK-Professional Middleware for IP Networking
|
FTP Server Routines enable the transfer of files to a FTP Client. More...
Functions | |
void | ftp_server_fclose (void *file) |
Close a file previously open in FTP server. | |
bool | ftp_server_fdelete (const char *fname) |
Delete a file in FTP server. | |
uint32_t | ftp_server_ffind (uint8_t code, char *buf, uint32_t buflen, const char *mask) |
Search the file system directory for matching files. | |
void * | ftp_server_fopen (const char *fname, const char *mode) |
Open a file for reading or writing in FTP server. | |
uint32_t | ftp_server_fread (void *file, uint8_t *buf, uint32_t len) |
Read block of data from a file in FTP server. | |
bool | ftp_server_frename (const char *fname, const char *newname) |
Rename a file or directory in FTP server. | |
void | ftp_server_notify (ftpServerEvent event) |
Notify the user application about events in FTP server service. | |
uint32_t | ftp_server_fwrite (void *file, const uint8_t *buf, uint32_t len) |
Write block of data to a file in FTP server. | |
bool | ftp_accept_client (const uint8_t *ip_addr, uint16_t port) |
Accept or deny connection from remote FTP client. | |
bool | ftp_check_password (uint8_t user_id, const char *password) |
Check user account password in the user database. | |
uint8_t | ftp_check_username (const char *username) |
Check if an user account exist in the user database. | |
bool | ftp_file_access (uint8_t user_id, const char *fname, uint8_t mode) |
Check if remote user is allowed to access a file on FTP server. | |
uint8_t | ftp_get_user_id (void) |
Retrieve the user identification. | |
enum | ftpCommand { ftpPUT, ftpGET, ftpAPPEND, ftpDELETE, ftpLIST, ftpRENAME, ftpMKDIR, ftpRMDIR, ftpNLIST } |
FTP Commands. More... | |
enum | ftpServerEvent { ftpServerLogin, ftpServerLogout, ftpServerLoginFailed, ftpServerDownload, ftpServerUpload, ftpServerDelete, ftpServerRename, ftpServerMakeDirectory, ftpServerRemoveDirectory, ftpServerOperationDenied, ftpServerLocalFileError, ftpServerFileError, ftpServerError } |
FTP Server Events. More... | |
FTP Server Routines enable the transfer of files to a FTP Client.
FTP routines are not reentrant.
enum ftpCommand |
FTP Commands.
Parameter for:
enum ftpServerEvent |
FTP Server Events.
Parameter for:
bool ftp_accept_client | ( | const uint8_t * | ip_addr, |
uint16_t | port | ||
) |
Accept or deny connection from remote FTP client.
[in] | ip_addr | IP address of the remote FTP client. |
[in] | port | port number of the remote FTP client. |
The function ftp_accept_client checks if a connection from the remote client is allowed or not. This enables remote client filtering. You can selectively decide which clients are allowed to connect to the FTP server and which are not.
The argument ip_addr points to a buffer containing the four octets that make up the IP address of the remote machine.
The argument port specifies the port on the remote machine.
The function is in the FTP_Server_Access.c module.
Code Example
bool ftp_check_password | ( | uint8_t | user_id, |
const char * | password | ||
) |
Check user account password in the user database.
[in] | user_id | user identification number. |
[in] | password | pointer to password. |
The function ftp_check_password authenticates the password for a specified user ID.
The argument user_id is the identification number of a user.
The argument password points to the password that gets checked.
Code Example
uint8_t ftp_check_username | ( | const char * | username | ) |
Check if an user account exist in the user database.
[in] | username | pointer to username. |
The function ftp_check_username authenticates the username and returns the corresponding identification number.
The argument username points to the user name. A value of 0 is returned if the user does not exist.
Code Example
bool ftp_file_access | ( | uint8_t | user_id, |
const char * | fname, | ||
uint8_t | mode | ||
) |
Check if remote user is allowed to access a file on FTP server.
[in] | user_id | user identification number. |
[in] | fname | name of a file to access. |
[in] | mode | access mode:
|
The function ftp_file_access checks if file access is allowed for a specific user. This allows access protection of sensitive files. The access to protected files will be blocked for unprivileged users. The error code "550 Access is denied" will be returned to the client if access is not allowed.
The argument user_id is the user identification number as returned by ftp_check_username. user_id identifies the user who is trying to access the specified file.
The argument fname points to a buffer containing the file name which should be accessed. The file name is a 0-terminated string.
The argument mode specifies the requested type of file access.
The function is in the FTP_Server_Multiuser.c module.
Code Example
uint8_t ftp_get_user_id | ( | void | ) |
Retrieve the user identification.
The function ftp_get_user_id retrieves the user identification number.
Code Example
void ftp_server_fclose | ( | void * | file | ) |
Close a file previously open in FTP server.
[in] | file | pointer to the file to close. |
The function ftp_server_fclose closes the file identified by the file stream pointer in the function argument.
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_Server_FS.c module.
bool ftp_server_fdelete | ( | const char * | fname | ) |
Delete a file in FTP server.
[in] | fname | name of the file to delete. |
The function ftp_server_fdelete deletes the file specified by fname from the server.
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_Server_FS.c module.
uint32_t ftp_server_ffind | ( | uint8_t | code, |
char * | buf, | ||
uint32_t | buflen, | ||
const char * | mask | ||
) |
Search the file system directory for matching files.
[in] | code | request type code:
|
[out] | buf | output buffer to write the listing to. |
[in] | buflen | length of the output buffer in bytes. |
[in] | mask | file mask filter. |
The function ftp_server_ffind searches the File System directory for files matching the specified mask filter mask. Matching file information is stored to the output buffer buf. The output data must be formatted in the FTP folder listing format.
The argument code specifies the request type:
Code | Request Type |
---|---|
0 | Read file size. |
1 | Read last-modified time of a file. |
2 | List file names only (first call). |
3 | List file directory in extended format (first call). |
4 | List file names only (subsequent call). |
5 | List file directory in extended format (subsequent call). |
The argument buflen specifies the size of output buffer buf.
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_Server_FS.c module.
void * ftp_server_fopen | ( | const char * | fname, |
const char * | mode | ||
) |
Open a file for reading or writing in FTP server.
[in] | fname | name of the file to open. |
[in] | mode | type of access:
|
The function ftp_server_fopen opens a file for reading or writing.
The argument fname specifies the name of the file to open.
The argument mode defines the type of access permitted for the file. The argument 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 does not exist. 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_Server_FS.c module.
uint32_t ftp_server_fread | ( | void * | file, |
uint8_t * | buf, | ||
uint32_t | len | ||
) |
Read block of data from a file in FTP server.
[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_server_fread reads len bytes from the file file stream pointer specified in the function argument.
The argument buf is a pointer to the buffer where the function stores the read data.
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_Server_FS.c module.
bool ftp_server_frename | ( | const char * | fname, |
const char * | newname | ||
) |
Rename a file or directory in FTP server.
[in] | fname | old name to rename from. |
[in] | newname | new name to rename to. |
The function ftp_server_frename renames the file name fname to newname on the server.
The argument fname must be the name of an existing file.
The argument newname must be a valid file name that does not exist in the scope.
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_Server_FS.c module.
uint32_t ftp_server_fwrite | ( | void * | file, |
const uint8_t * | buf, | ||
uint32_t | len | ||
) |
Write block of data to a file in FTP server.
[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_server_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_Server_FS.c module.
void ftp_server_notify | ( | ftpServerEvent | event | ) |
Notify the user application about events in FTP server service.
[in] | event | FTP Server notification event |
The function ftp_server_notify notifies the user application about events in FTP server. This function is useful to synchronize various actions, such as firmware upgrade, to FTP server events. The firmware upgrade might start after the ftpServerLogout event is signalled and a new firmware image file has been uploaded to the server.
Code Example