共用方式為


CFtpFileFind Class

Aids in Internet file searches of FTP servers.

class CFtpFileFind : public CFileFind

Members

Public Constructors

Name

Description

CFtpFileFind::CFtpFileFind

Constructs a CFtpFileFind object.

Public Methods

Name

Description

CFtpFileFind::FindFile

Finds a file on a FTP server.

CFtpFileFind::FindNextFile

Continues a file search from a previous call to FindFile.

CFtpFileFind::GetFileURL

Gets the URL, including path, of the found file.

Remarks

CFtpFileFind includes member functions that begin a search, locate a file, and return the URL or other descriptive information about the file.

Other MFC classes designed for Internet and local file searched include CGopherFileFind and CFileFind. Together with CFtpFileFind, these classes provide a seamless mechanism for the client to find specific files, regardless of the server protocol or file type (either a local machine or a remote server). Note that there is no MFC class for searching on HTTP servers because HTTP does not support the direct file manipulation required for searches.

For more information about how to use CFtpFileFind and the other WinInet classes, see the article Internet Programming with WinInet.

Example

The following code demonstrates how to enumerate all files in the current directory of the FTP server.

// create a session object to initialize WININET library 
// Default parameters mean the access method in the registry 
// (that is, set by the "Internet" icon in the Control Panel)
// will be used.

CInternetSession sess(_T("My FTP Session"));

CFtpConnection* pConnect = NULL;

try
{
   // Request a connection to ftp.microsoft.com. Default 
   // parameters mean that we'll try with username = ANONYMOUS 
   // and password set to the machine name @ domain name
   pConnect = sess.GetFtpConnection(_T("ftp.microsoft.com"));

   // use a file find object to enumerate files
   CFtpFileFind finder(pConnect);

   // start looping
   BOOL bWorking = finder.FindFile(_T("*"));

   while (bWorking)
   {
      bWorking = finder.FindNextFile();
      _tprintf_s(_T("%s\n"), (LPCTSTR)finder.GetFileURL());
   }
}
catch (CInternetException* pEx)
{
   TCHAR sz[1024];
   pEx->GetErrorMessage(sz, 1024);
   _tprintf_s(_T("ERROR!  %s\n"), sz);
   pEx->Delete();
}

// if the connection is open, close it 
if (pConnect != NULL) 
{
   pConnect->Close();
   delete pConnect;
}

Inheritance Hierarchy

CObject

CFileFind

CFtpFileFind

Requirements

Header: afxinet.h

See Also

Reference

CFileFind Class

Hierarchy Chart

CGopherFileFind Class

CInternetFile Class

CGopherFile Class

CHttpFile Class