ftpDirCatalogGet (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

2.10 / 1.00.00


This function will fetch the contents of the current directory on the FTP server

To read the actual entries in the list, use ftpDirCatalog.

 

The list will only contain files or sub-directories, and the order is as received by the server.

 

Note:

If "Name" is used, this is sent unchecked to the server as an option to the FTP command and can on most servers be used to filter the names listed e.g. "*.jpg" or "/log/*.log".

Only the first 64 names that match the 8.3 file format are fetched if using this function.

 

 

Input:

ID : INT

The ID returned from ftpConnect.

 

Dir : BOOL (default FALSE)

List directories or files.

 

Name : STRING (Optional)

If empty, all names in current directory are requested.

 

Returns: INT

Number of names in catalog.

- 1


- Failed to fetch list of files, see ftpLastResponse.

- 2


- Invalid ID.

- 4


- Session is busy with another operation.

- 5


- FTP not open, use ftpOpen to open interface.

- 10


- Communication with server not possible.

 

Declaration:

FUNCTION ftpDirCatalogGet : INT;
VAR_INPUT
  ID     : INT;
  Name   : STRING := "";
  Dir    : BOOL   := FALSE;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM example;
VAR
  open : BOOL;
  host : STRING := "ftp.domain.com";
  usr   : STRING := "ftpuser";
  pwd   : STRING := "user pwd";
 
  id   : INT;
 
  count : INT;
  rc, i : INT;
  name : STRING;
  size : DINT;
END_VAR;
 
  gsmPower(power := ON);
  gprsOpen();
 
BEGIN
 open := (ftpOpen() = 0);
IF open THEN
    id := ftpConnect(host := host, username := usr, password := pwd);
    count := ftpDirCatalogGet(id := id);
   
    FOR i := 1 TO count DO
      rc := ftpDirCatalog(id := id, index := i, name := name, size := size);
      CASE rc OF
        1 : DebugFmt(message := "File name = '" + name +"' size = \4", v4 := size);
        2 : DebugFmt(message := "Dir  name = '" + name +"' size = \4", v4 := size);
      END_CASE;
    END_FOR;
 
    ftpDisconnect(id := id);
END_IF;
ftpClose();
END;
END_PROGRAM;