CFtpConnection CFtpFileFind #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 /GXCWinApp 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; }VC自带Sample中含有ftptree例程!
FtpDeleteFile
FtpFindFirstFile
FtpGetCurrentDirectory
FtpGetFile
FtpOpenFile
FtpPutFile
FtpRemoveFile
FtpSetCurrentDirectory
//首先在服务器端的FTP主目录下放一个Config.txt的文本文件,
CInternetSession session;
//连接FTP Server
CFtpConnection *TempFtp=session.GetFtpConnection("dbs","Administrator","123321");
//下载文件
TempFtp->GetFile("Config.txt","e:\\ee.txt",TRUE,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_ASCII,1);
//处理文件
FILE *fp;
fp=fopen("e:\\ee.txt","a+");
fprintf(fp,"\nAdd Line\n");
fclose(fp);
//上传文件
TempFtp->PutFile("e:\\ee.txt","Config.txt",FTP_TRANSFER_TYPE_ASCII,1);
//关闭连接
TempFtp->Close();
session.Close();
//OK
CFtpFileFind
#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 /GXCWinApp 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;
}VC自带Sample中含有ftptree例程!
ahphone(阿丰) 的类好象不存在!
我最近比较忙,别的朋友的办法还没有试,分我肯定会给的,再次感谢!