Network Component  Version 7.11.0
MDK Middleware for IPv4 and IPv6 Networking
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
File System Interface

FTP server functions that work with a File System. More...

Functions

void * netFTPs_fopen (const char *fname, const char *mode)
 Open a file for reading or writing in FTP server. [interface]. More...
 
void netFTPs_fclose (void *file)
 Close a file previously open in FTP server. [interface]. More...
 
uint32_t netFTPs_fread (void *file, uint8_t *buf, uint32_t len)
 Read block of data from a file in FTP server. [interface]. More...
 
uint32_t netFTPs_fwrite (void *file, const uint8_t *buf, uint32_t len)
 Write block of data to a file in FTP server. [interface]. More...
 
bool netFTPs_fdelete (const char *fname)
 Delete a file in FTP server. [interface]. More...
 
bool netFTPs_frename (const char *fname, const char *newname)
 Rename a file or directory in FTP server. [interface]. More...
 
bool netFTPs_mkdir (const char *path)
 Make a new directory in FTP server. [interface]. More...
 
bool netFTPs_rmdir (const char *path)
 Remove an empty directory in FTP server. [interface]. More...
 
uint32_t netFTPs_ffind (uint8_t code, char *buf, uint32_t buf_len, const char *mask)
 Search the file system directory for matching files. [interface]. More...
 

Description

FTP server functions that work with a File System.

All File System Interface functions are located in FTP_Server_FS.c, which will be automatically added to your project's Network folder. The file is preconfigured for the component, so no modifications are required. If you wish to use another type of file system, you need to override these weak procedures with your required functionality.

The following functions are implemented in this module:

Function Documentation

void netFTPs_fclose ( void *  file)

Close a file previously open in FTP server. [interface].

Parameters
[in]filepointer to the file to close.
Returns
none.

The function netFTPs_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 netFTPs_fdelete ( const char *  fname)

Delete a file in FTP server. [interface].

Parameters
[in]fnamename of the file to delete.
Returns
  • true = File successfully deleted.
  • false = Failed to delete a file.

The function netFTPs_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 netFTPs_ffind ( uint8_t  code,
char *  buf,
uint32_t  buf_len,
const char *  mask 
)

Search the file system directory for matching files. [interface].

Parameters
[in]coderequest type code:
  • 0 = Retrieve file size.
  • 1 = Retrieve last-modified time of a file.
  • 2 = List files by name, first call.
  • 3 = List files in extended format, first call.
  • 4 = List files by name, subsequent call.
  • 5 = List files in extended format, subsequent call.
[out]bufoutput buffer to write the listing to.
[in]buf_lenlength of the output buffer in bytes.
[in]maskfile mask filter.
Returns
number of bytes written to output buffer.

The function netFTPs_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.

Note
Currently, the function netFTPs_ffind requires the File System Component of the MDK-Professional Middleware to be present.

The argument code specifies the request type:

CodeRequest 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 buf_len 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 * netFTPs_fopen ( const char *  fname,
const char *  mode 
)

Open a file for reading or writing in FTP server. [interface].

Parameters
[in]fnamename of the file to open.
[in]modetype of access:
  • "rb" = opens a file for reading.
  • "wb" = opens a file for writing.
Returns
status information:
  • Pointer to an open file.
  • NULL in case of an error.

The function netFTPs_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:

ModeDescription
"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 netFTPs_fread ( void *  file,
uint8_t *  buf,
uint32_t  len 
)

Read block of data from a file in FTP server. [interface].

Parameters
[in]filepointer to the file to read from.
[out]bufblock of memory to write data to.
[in]lenlength of data to read in bytes.
Returns
number of bytes successfully read.

The function netFTPs_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.

Note
The function must read len bytes. The FTP server stops reading and closes the file if the return value is less than len bytes.
bool netFTPs_frename ( const char *  fname,
const char *  newname 
)

Rename a file or directory in FTP server. [interface].

Parameters
[in]fnameold name to rename from.
[in]newnamenew name to rename to.
Returns
  • true = File or directory successfully renamed.
  • false = Failed to rename a file or directory.

The function netFTPs_frename renames a file specified by 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 netFTPs_fwrite ( void *  file,
const uint8_t *  buf,
uint32_t  len 
)

Write block of data to a file in FTP server. [interface].

Parameters
[in]filepointer to the file to write to.
[in]bufblock of memory to be written.
[in]lenlength of data to write in bytes.
Returns
number of bytes successfully written.

The function netFTPs_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.

Note
The FTP server stops writing and closes the file if the return value is less than len bytes.
bool netFTPs_mkdir ( const char *  path)

Make a new directory in FTP server. [interface].

Parameters
[in]pathdirectory path to create.
Returns
  • true = Directory successfully created.
  • false = Failed to create a directory.

The function netFTPs_mkdir creates a new directory on the FTP server for file storage. On success, it returns true.

The argument path is a pointer to the directory's name.

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 netFTPs_rmdir ( const char *  path)

Remove an empty directory in FTP server. [interface].

Parameters
[in]pathdirectory path to remove.
Returns
  • true = Directory successfully removed.
  • false = Failed to remove a directory.

The function netFTPs_rmdir deletes a directory on the FTP server. On success, it returns true.

The argument path is a pointer to the directory's name.

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.