ftp查找文件
怎样实现在一个ftp服务器的特定目录下查找一个指定的文件是否存在?
#include
#include
#include
#include
// compile for release with
// cl /MT /GX
// or for debug with
// cl /MTd /GX
CWinApp theApp;
void main()
{
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// catastropic error! MFC can't initialize
return;
}
// 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;
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();
printf("%s\n", (LPCTSTR) finder.GetFileURL());
}
}
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf("ERROR! %s\n", sz);
pEx->Delete();
}
// if the connection is open, close it
if (pConnect != NULL)
pConnect->Close();
delete pConnect;
return;
}
Requirements
Header: afxinet.h
怎样实现在一个ftp服务器的特定目录下查找一个指定的文件是否存在?
#include
#include
#include
#include
// compile for release with
// cl /MT /GX
// or for debug with
// cl /MTd /GX
CWinApp theApp;
void main()
{
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// catastropic error! MFC can't initialize
return;
}
// 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;
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();
printf("%s\n", (LPCTSTR) finder.GetFileURL());
}
}
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf("ERROR! %s\n", sz);
pEx->Delete();
}
// if the connection is open, close it
if (pConnect != NULL)
pConnect->Close();
delete pConnect;
return;
}
Requirements
Header: afxinet.h