[MFC] Cum fac upload folosind FTP?

Despre MFC, ATL si alte biblioteci C++ de la Microsoft (forum moderat)
Post Reply
mesajflaviu
Membru++
Membru++
Posts: 687
Joined: 10 Sep 2008, 21:40
Judet: Cluj

[MFC] Cum fac upload folosind FTP?

Post by mesajflaviu » 31 Jan 2011, 13:39

Intrebare: Cum fac upload folosind FTP?

Raspuns: In MFC se poate face cu CFtpConnection::PutFile.

Exemplu

Code: Select all

void CFtpDoc::UploadFile(const CString& strPathName,
                         LPCTSTR pszServer, LPCTSTR pszUserName, LPCTSTR pszPasword,
                         LPCTSTR pszRemotePath)
{
   CInternetSession session;
   CString strFileName = 
      strPathName.Right(strPathName.GetLength() - strPathName.ReverseFind('\\') - 1);
   CFtpConnection* pConn = session.GetFtpConnection(pszServer, pszUserName, pszPasword);
   if(NULL != pConn)
   {
      if(!pConn->PutFile(strPathName, pszRemotePath + strFileName))
      {
         CString strMessage;
         strMessage.Format(_T("Upload failed. Error: %u"), ::GetLastError());
         AfxMessageBox(strMessage, MB_ICONERROR);
      }
      pConn->Close();
      delete pConn;
   }
}

Code: Select all

void CFtpDoc::OnUploadFile() 
{
// just demo; here may be an open file dialog and/or other stuff.
// ...
   try
   {
      //...
      UploadFile(strPathName, strServer, strUser, strPassword, strRemotePath);
   }
   catch(CException* pException)
   {
      pException->ReportError();
      pException->Delete();
   }
}
Vezi si << Back to MFC index



Post Reply