L_InetFtpBrowseDir

#include "ltweb.h"

L_LTWEB_API L_INT L_InetFtpBrowseDir(hFtp, pszSearch, pfnCallback, pData)

HFTP hFtp;

/* handle to an FTP connection */

L_TCHAR *pszSearch;

/* directory path or file name */

FTPBROWSECALLBACK pfnCallback;

/* pointer to a callback function */

L_VOID *pData;

/* pointer to additional parameters */

Browses a specific directory or searches for a specific file on an FTP server's file system.

Parameter

Description

hFtp

Valid HFTP handle to an FTP connection.

pszSearch

Character string that contains a valid directory path or file name for the FTP server's file system. The string can contain wildcards, but no blank spaces are allowed. If the value of pszSearch is NULL or if it is an empty string, it will find the first file in the current directory on the server. This is a NULL-terminated string.

pfnCallback

Optional callback function that will receive the data found during the browse/search.

  • If you do not provide a callback function, use NULL as the value of this parameter.

  • If you do provide a callback function, use the function pointer as the value of this parameter.

 

The callback function must adhere to the function prototype described in the FTPBROWSECALLBACK Function.

pData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.

 

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID  *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.

 

If the additional parameters are not needed, you can pass NULL in this parameter.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Searches the specified directory of the given FTP connection. File and directory entries are returned to the application in the FILEDATA structure of the callback function.

Required DLLs and Libraries

LTWEB
LTFIL

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application

See Also

Functions:

FTPBROWSECALLBACK, L_InetFtpCreateDir, L_InetFtpChangeDir

Topics:

FTP Functions: Directory Manipulation Over an FTP Connection

 

How to Program with FTP Functions

Example

This example connects to an ftp server and browses a directory. If found it adds files to a list.

L_VOID AddFileToList(L_TCHAR * pszFileName,L_UINT32  uSize)
{
   UNREFERENCED_PARAMETER(uSize);
   UNREFERENCED_PARAMETER(pszFileName);
   // Process file data here
}
L_INT CALLBACK BrowseDirCallBack(L_TCHAR * pszFile,
                                 pFILEDATA pFileData,
                                 L_VOID  * pUserData) 
{
   UNREFERENCED_PARAMETER(pUserData);
   AddFileToList(pszFile, pFileData->uFileSize);
   return SUCCESS;
}
 L_INT InetFtpBrowseDirExample(L_TCHAR * pszDirName,
                                              L_TCHAR * pszServerName,
                                              L_TCHAR * pszUserName,
                                              L_TCHAR * pszPassword)
{
   HFTP hFtp;
   L_INT nRetCode = SUCCESS; 
   L_INT iPort = 21; //Deafult ftp port
   nRetCode = L_InetFtpConnect(pszServerName, iPort, pszUserName, pszPassword, &hFtp); 
   if(nRetCode==SUCCESS)
   {
      nRetCode = L_InetFtpBrowseDir(hFtp, pszDirName, (FTPBROWSECALLBACK) BrowseDirCallBack, NULL);
      if(nRetCode != SUCCESS)
         return nRetCode;
   }
   else
      return nRetCode;
   nRetCode = L_InetFtpDisConnect(hFtp);
   if(nRetCode != SUCCESS)
      return nRetCode;
   return nRetCode; 
}