请问:
    
      VC下如何编程可以访问FTP,并从FTP上读取数据呢?      谢谢大家了

解决方案 »

  1.   

    void CDoHTMLAppDlg::FtpWriteFile(CString strFilePath)
    {
    CInternetSession *pInetSession;
    CFtpConnection *pFtpConnection=NULL;
    CString strFileName;
    pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
    try
    {
    pFtpConnection=pInetSession->GetFtpConnection("10.70.38.109");
    }
    catch(CInternetException *pEx)
    {
    char strErrorBuf[255];
    pEx->GetErrorMessage(strErrorBuf,255,NULL);
    AfxMessageBox(strErrorBuf,MB_ICONINFORMATION); pEx->Delete();
    pFtpConnection=NULL;
    goto FinishByDigitalTitan;
    }
    strFileName=strFilePath.Mid(strFilePath.ReverseFind('\\')+1);
    //AfxMessageBox(strFileName,MB_ICONINFORMATION);
    pFtpConnection->Remove(strFileName);
    if(pFtpConnection->PutFile(strFilePath,strFileName)!=0)
    {}
    else
    {
    LPVOID lpMsgBuf;
    ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,0,GetLastError(),MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,0,NULL);
    ::MessageBox(0,(LPCTSTR)lpMsgBuf,_T("GetLastError"),MB_OK|MB_ICONINFORMATION);
    ::LocalFree(lpMsgBuf);
    }
    FinishByDigitalTitan:
    if(pFtpConnection!=NULL)
    {
    pFtpConnection->Close();
    delete pFtpConnection;
    }
    delete pInetSession;
    }