我要写一个下载程序,功能很简单,只访问服务器然后下载文件,请问该如何实现?最好有代码说明,谢谢先!!!

解决方案 »

  1.   

    可以使用FTP,有相关的MFC类。
      

  2.   

    那你不妨用用WiniNet函数集,Microsoft实现的,用起来比较好用。
    MSDN找wininet就可以了。
      

  3.   

    如果文件小,可以使用CFtpConnection中的GetFile功能,如果文件大则使用CFtpConnection中的OpenFile打开文件后,使用CInternetFile的Read功能。
    例子可以看看MSDN中的FTPTree
      

  4.   

    CInternetSession sessionSzzs("test");
    CHttpFile* pSzzsFile = (CHttpFile*)(sessionSzzs.OpenURL(_T("http://www.XXX.com/1.zip")));
    if(pSzzsFile != NULL)
    {
    CFile szzsTargetFile;
    BOOL bResult = szzsTargetFile.Open(_T("c:\\1.zip"), 
    CFile::modeCreate | CFile::modeWrite);
    if(!bResult)
    return FALSE;
    while(bResult)
    {
    char* chBuff = new char[1025];
    UINT nCount = pSzzsFile->Read(chBuff, 1024);
    if(nCount > 0)
    szzsTargetFile.Write(chBuff, nCount);
    else
    {
    szzsTargetFile.Close();
    pSzzsFile->Close();
    delete pSzzsFile;
    break ;
    }
    }
    }
      

  5.   

    试试dongfa给的例子,我已经试过了,没问题的!
      

  6.   

    to:Rodgu(棒子)    需要写什么头文件?error C2065: 'CInternetSession' : undeclared identifier等等错误...???
      

  7.   

    看MSDN,需要#include <afxinet.h>
      

  8.   

    我在CDialog中用dongfa(阿东)的代码,却抱以下错误:
    Compiling...
    downloadDlg.cpp
    E:\aa\download\downloadDlg.cpp(100) : error C2065: 'CInternetSession' : undeclared identifier
    E:\aa\download\downloadDlg.cpp(100) : error C2146: syntax error : missing ';' before identifier 'sessionSzzs'
    E:\aa\download\downloadDlg.cpp(100) : error C2065: 'sessionSzzs' : undeclared identifier
    E:\aa\download\downloadDlg.cpp(101) : error C2065: 'CHttpFile' : undeclared identifier
    E:\aa\download\downloadDlg.cpp(101) : error C2065: 'pSzzsFile' : undeclared identifier
    E:\aa\download\downloadDlg.cpp(101) : error C2059: syntax error : ')'
    E:\aa\download\downloadDlg.cpp(108) : error C2562: 'OnOK' : 'void' function returning a value
            e:\aa\download\downloaddlg.h(41) : see declaration of 'OnOK'
    E:\aa\download\downloadDlg.cpp(112) : error C2227: left of '->Read' must point to class/struct/union
    E:\aa\download\downloadDlg.cpp(118) : error C2227: left of '->Close' must point to class/struct/union
    E:\aa\download\downloadDlg.cpp(119) : error C2541: delete : cannot delete objects that are not pointers
    Error executing cl.exe.download.exe - 10 error(s), 0 warning(s)