http://msdn.microsoft.com/en-US/library/272ce2aa(v=vs.80)// cftpfilefind_class.cpp // Compile with: /MT /EHsc #include <afx.h> #include <afxwin.h> #include <afxinet.h> #include <stdio.h>CWinApp theApp;int main() { if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // catastropic error! MFC can't initialize return -1; } // 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("%s\n", (LPCTSTR) finder.GetFileURL()); } } catch (CInternetException* pEx) { TCHAR sz[1024]; pEx->GetErrorMessage(sz, 1024); printf_s("ERROR! %s\n", sz); pEx->Delete(); } // if the connection is open, close it if (pConnect != NULL) { pConnect->Close(); delete pConnect; } return 0; }刚回答的一个帖子
afx_msg void OnConnect();
afx_msg void OnSend();
afx_msg void OnDisconnect();
afx_msg void OnCreatedir();
afx_msg void OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnFatherdir();
afx_msg void OnDel();
你去看看工程中以上这几个函数的实现即可
CFtpConnection *m_pFtpConnection;
-----------------------
应该用的WININET的东西,相关的部分参考MSDN文档即可
// Compile with: /MT /EHsc
#include <afx.h>
#include <afxwin.h>
#include <afxinet.h>
#include <stdio.h>CWinApp theApp;int main()
{
if (!AfxWinInit(::GetModuleHandle(NULL), NULL,
::GetCommandLine(), 0))
{
// catastropic error! MFC can't initialize
return -1;
} // 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("%s\n", (LPCTSTR) finder.GetFileURL());
}
}
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf_s("ERROR! %s\n", sz);
pEx->Delete();
} // if the connection is open, close it
if (pConnect != NULL)
{
pConnect->Close();
delete pConnect;
} return 0;
}刚回答的一个帖子
CFtpConnection
CFtpFileFind主要的大概就是如下这些,看MSDN就可以了
GetFtpConnection --建立连接
GetCurrentDirectory --获取当前目录
CFtpFileFind -- FindFile --枚举文件列表
PutFile --上传文件
GetFile --下载文件
Close --关闭连接