CFtpFileFind选件类

在Internet FTP服务器文件搜索的帮助。

class CFtpFileFind : public CFileFind

成员

272ce2aa.collapse_all(zh-cn,VS.110).gif公共构造函数

名称

说明

CFtpFileFind::CFtpFileFind

构造 CFtpFileFind 对象。

272ce2aa.collapse_all(zh-cn,VS.110).gif公共方法

名称

说明

CFtpFileFind::FindFile

查找在FTP服务器的文件。

CFtpFileFind::FindNextFile

继续以前的文件搜索调用 FindFile

CFtpFileFind::GetFileURL

获取URL,其中包含路径,则找到文件。

备注

CFtpFileFind 包括开始搜索,查找文件,并返回URL或其他描述性信息有关文件的成员函数。

对于Internet和本地文件模型中的其他MFC选件类中搜索包含 CGopherFileFindCFileFind。 无论服务器协议或文件类型(本地计算机或远程服务器),而 CFtpFileFind时,这些选件类为客户端提供一种无缝的结构以查找特定的文件。 请注意不要搜索的MFC选件类在HTTP服务器,因为HTTP不支持对于搜索所需的直接文件。

有关如何使用 CFtpFileFind 和其他WinInet选件类的更多信息,请参见文章 编程时WinInet的Internet

示例

下面的代码演示如何枚举在FTP服务器上的当前目录中的所有文件。

// 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;
}

继承层次结构

CObject

CFileFind

CFtpFileFind

要求

Header: afxinet.h

请参见

参考

CFileFind选件类

层次结构图

CGopherFileFind选件类

CInternetFile选件类

CGopherFile选件类

CHttpFile选件类