WebFtpListDirectory Function

Action

Searches the specified directory of the given FTP session and retrieves a directory listing of the path specified in sSearchPath. If you want to access the data of the directory listing, use WebFtpFindFirstFile and WebFtpFindNextFile instead, as illustrated in the example below.

Include file

WebAPI.bdh

Syntax

WebFtpListDirectory( in hFtp        : number, 
                     in sSearchPath : string optional ): boolean;

Return value

  • true if the directory list was started successfully

  • false otherwise

Parameter Description
hFtp Valid handle to an FTP session. This handle must have been returned from a previous call to WebFtpConnect.
sSearchPath String that specifies a valid directory path or file name for the FTP server's file system. If the value of sSearchPath is NULL or if it is an empty string, this function will find the first file in the current directory on the server (optional).
Note: If the function finds no matching files, it returns false.

Example

// Connect to the ftp server and list the root directory 
// 1) using WebFtpFindFirstFile, WebFtpFindNextFile in loops 
// 2) using only the command WebFtpListDirectory 
dcltrans 
  transaction TWebFtpListDir 
  var
    hFtp       : number;
    sFileName  : string(MAX_PATH);
    nAttribute : number;
    nFiles     : number;
    bOk        : boolean; 
  begin
    WebFtpConnect(hFtp, "standardhost", WEB_PORT_FTP, "", "");
    nFiles := 0;

    // Custom directory list enumeration
    bOk := WebFtpFindFirstFile(hFtp, "", sFileName,
                               MAX_PATH, nAttribute);

    while bOk do 
      write(sFileName); write(" "); write(nAttribute); writeln;
      nFiles := nFiles + 1;
      bOk := WebFtpFindNextFile(hFtp, sFileName,
                                MAX_PATH, nAttribute); 
    end;
 
    if nAttribute = WEB_FTP_FA_NO_MORE_FILES then 
      write(nFiles); write(" files found"); writeLn; 
    else 
      write("Error retrieving directory information!"); 
      writeln; 
    end;
 
    // This command sends the FTP commands to get a directory list 
    WebFtpListDirectory(hFtp, "");
    WebFtpShutdown(hFtp); 
  end TWebFtpListDir;

SilkEssential sample

Ftp.sep