How can I upload an file in MFC ?
-
I test MFC classes to download files from internet server , but how can I upload it ? Can I use the same classes / tehnique ?
-
I test MFC classes to download files from internet server , but how can I upload it ? Can I use the same classes / tehnique ?
mesajflaviu wrote:
Can I use the same classes / tehnique ?
Most likely, but since you did not show any specifics on how you were downloading, we can't say with any certainty.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
mesajflaviu wrote:
Can I use the same classes / tehnique ?
Most likely, but since you did not show any specifics on how you were downloading, we can't say with any certainty.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
Ok , here is my download code , which goes perfectly : ( I don't know if is corectly , but does function )
BOOL CMyDoc::GetXmlFile(CString sAddress, CString& sResult)
{
CString sTemp;
CInternetSession ISession;
CInternetFile* pIFile = NULL;
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();try { pIFile = (CInternetFile\*)ISession.OpenURL(sAddress); while(pIFile->ReadString(sTemp))sResult += sTemp; pIFile->Close(); delete pIFile; } catch(CException\* pException) { delete pIFile; pException->GetErrorMessage(sTemp.GetBuffer(255),255); sTemp.ReleaseBuffer(); pFrame->SetMessageText(sTemp); return FALSE; } return TRUE;
}
I will be very glad if you can help me . Thank you very much !
-
Ok , here is my download code , which goes perfectly : ( I don't know if is corectly , but does function )
BOOL CMyDoc::GetXmlFile(CString sAddress, CString& sResult)
{
CString sTemp;
CInternetSession ISession;
CInternetFile* pIFile = NULL;
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();try { pIFile = (CInternetFile\*)ISession.OpenURL(sAddress); while(pIFile->ReadString(sTemp))sResult += sTemp; pIFile->Close(); delete pIFile; } catch(CException\* pException) { delete pIFile; pException->GetErrorMessage(sTemp.GetBuffer(255),255); sTemp.ReleaseBuffer(); pFrame->SetMessageText(sTemp); return FALSE; } return TRUE;
}
I will be very glad if you can help me . Thank you very much !
So then can't you just use
WriteString()
to upload the file?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
So then can't you just use
WriteString()
to upload the file?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
David , you are very prompt ! Thank you ! But , if I need to upload an file , don't need an login data to access upload server ?
-
David , you are very prompt ! Thank you ! But , if I need to upload an file , don't need an login data to access upload server ?
mesajflaviu wrote:
But , if I need to upload an file , don't need an login data to access upload server ?
Maybe, maybe not. Only you will know that level of detail. You might look into
CHttpFile::SendRequest()
."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
mesajflaviu wrote:
But , if I need to upload an file , don't need an login data to access upload server ?
Maybe, maybe not. Only you will know that level of detail. You might look into
CHttpFile::SendRequest()
."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
Maybe ( or for sure ) I don't understand something : I have an address to an server : 'http://www.testserver.com/testfolder/' and in this location ( path ) I want to upload an PC local path file : 'D:/Flaviu/test.txt' ... How can I adapt download code from above to write strings into server file ? First , create an mirror text file on server , and there write strings from PC local txt file ?
-
Maybe ( or for sure ) I don't understand something : I have an address to an server : 'http://www.testserver.com/testfolder/' and in this location ( path ) I want to upload an PC local path file : 'D:/Flaviu/test.txt' ... How can I adapt download code from above to write strings into server file ? First , create an mirror text file on server , and there write strings from PC local txt file ?
I found the solution , and for those hwo have the same issue , I post the code :
BOOL CMyDoc::UploadFile(CString sFileName)
{
CString sTemp;
BOOL bRet = FALSE;
CInternetSession session;
CFtpConnection* pConn = NULL;
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
sTemp = sFileName.Right(sFileName.GetLength() - sFileName.ReverseFind('\\') - 1);try { pConn = session.GetFtpConnection(\_T("ftp.domain.com"),\_T("username"),\_T("password"),INTERNET\_INVALID\_PORT\_NUMBER,TRUE); bRet = pConn->PutFile(sFileName,\_T("./httpdocs/temp/") + sTemp); } catch(CException\* pException) { pException->GetErrorMessage(sTemp.GetBuffer(255),255); sTemp.ReleaseBuffer(); pException->Delete(); pFrame->SetMessageText(sTemp); } if(pConn) { pConn->Close(); delete pConn; } return bRet;
}