CFtpFileFind Class
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

CFtpFileFind Class

class CFtpFileFind : public CFileFind


Class CFtpFileFind aids in Internet file searches of FTP servers. 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.


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

#include <afx.h>
#include <afxwin.h>
#include <afxinet.h>
#include <stdio.h>

// compile for release with
//   cl /MT /GX
// or for debug with
//   cl /MTd /GX

CWinApp theApp;

int main()
   if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
      // catastropic error! MFC can't initialize

   // 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("MyProgram/1.0"));

   CFtpConnection* pConnect = NULL;

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

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

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

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

   // if the connection is open, close it
   if (pConnect != NULL)
   delete pConnect;



Header: afxinet.h

See Also

Class Members | Base Class | Hierarchy Chart | CGopherFileFind | CInternetFile | CGopherFile | CHttpFile

© 2016 Microsoft