Network Component  
MDK Middleware for IPv4 and IPv6 Networking
 
Loading...
Searching...
No Matches
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 on FTP server. [interface].
 
void netFTPs_fclose (void *file)
 Close a file previously open on FTP server. [interface].
 
uint32_t netFTPs_fread (void *file, uint8_t *buf, uint32_t len)
 Read block of data from a file on FTP server. [interface].
 
uint32_t netFTPs_fwrite (void *file, const uint8_t *buf, uint32_t len)
 Write block of data to a file on FTP server. [interface].
 
bool netFTPs_fdelete (const char *fname)
 Delete a file on FTP server. [interface].
 
bool netFTPs_frename (const char *fname, const char *newname)
 Rename a file or directory on FTP server. [interface].
 
bool netFTPs_mkdir (const char *path)
 Make a new directory on FTP server. [interface].
 
bool netFTPs_rmdir (const char *path)
 Remove an empty directory on FTP server. [interface].
 
bool netFTPs_chdir (const char *path)
 Check that the directory exists on FTP server. [interface].
 
int32_t netFTPs_ffind (const char *mask, char *fname, uint32_t *fsize, NET_FS_TIME *ftime, bool first)
 Search the file system directory for matching files. [interface].
 

Description

FTP server functions that work with a File System.

All functions of the File System Interface are located in FTP_Server_FS.c, which is automatically added to the Network folder of your project. The file is preconfigured for the , so no changes are required. If you want to use a different type of file system, you must add a similar file to your project and implement the interface functions yourself.

The following functions are implemented in this module:

Function Documentation

◆ netFTPs_chdir()

bool netFTPs_chdir ( const char *  path)

Check that the directory exists on FTP server. [interface].

Parameters
[in]pathdirectory path to check.
Returns
  • true = Directory exists.
  • false = Directory not found.

The function netFTPs_chdir verifies that specified directory exists on the FTP server. On success, it returns true. If the file system on the FTP server storage device does not support directories, the function must always return false.

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.

◆ netFTPs_fclose()

void netFTPs_fclose ( void *  file)

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

Parameters
[in]filepointer to the file to close.

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.

◆ netFTPs_fdelete()

bool netFTPs_fdelete ( const char *  fname)

Delete a file on 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.

◆ netFTPs_ffind()

int32_t netFTPs_ffind ( const char *  mask,
char *  fname,
uint32_t *  fsize,
NET_FS_TIME ftime,
bool  first 
)

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

Parameters
[in]maskfile mask filter.
[out]fnamebuffer to write filename to.
  • NULL for none.
[out]fsizepointer to where to return the file size.
  • NULL for none.
[out]ftimepointer to where to return the created or last modified time.
  • NULL for none.
[in]firstfind first file.
Returns
status information:
  • NET_FS_ATTR_FILE = File found.
  • NET_FS_ATTR_DIRECTORY = Directory found.
  • 0 = No entry found.

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 fname, fsize and ftime. The output data is then processed in FTP server and formatted in the FTP folder listing format.

The argument fname is a pointer to a buffer, where the file name is going to be stored. If this argument is NULL, the file name is not requested and is not saved.

The argument fsize is a pointer to where the file size is going to be stored. If this argument is NULL, the file size is not requested and is not saved.

The argument ftime is a pointer to a structure, that will receive the last modification time of a file. If this argument is NULL, the last modification time is not requested and is not saved.

The argument first has a value of true when the first file is requested. On all subsequent calls, the argument first has a value of false. It is used to initialize the file search engine in the File System Component.

This function returns the following values:

Return Value Description
NET_FS_ATTR_FILE The entry found is a file
NET_FS_ATTR_DIRECTORY The entry found is a directory
0 No entry found
Note
Currently, the function netFTPs_ffind requires the File System Component of the MDK-Professional Middleware to be present.

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.

◆ netFTPs_fopen()

void * netFTPs_fopen ( const char *  fname,
const char *  mode 
)

Open a file for reading or writing on 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:

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.

◆ netFTPs_fread()

uint32_t netFTPs_fread ( void *  file,
uint8_t *  buf,
uint32_t  len 
)

Read block of data from a file on 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.

◆ netFTPs_frename()

bool netFTPs_frename ( const char *  fname,
const char *  newname 
)

Rename a file or directory on 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.

◆ netFTPs_fwrite()

uint32_t netFTPs_fwrite ( void *  file,
const uint8_t *  buf,
uint32_t  len 
)

Write block of data to a file on 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.

◆ netFTPs_mkdir()

bool netFTPs_mkdir ( const char *  path)

Make a new directory on 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.

◆ netFTPs_rmdir()

bool netFTPs_rmdir ( const char *  path)

Remove an empty directory on 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.