Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How can I upload an file in MFC ?

How can I upload an file in MFC ?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++sysadmin
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mesajflaviu
    wrote on last edited by
    #1

    I test MFC classes to download files from internet server , but how can I upload it ? Can I use the same classes / tehnique ?

    D 1 Reply Last reply
    0
    • M mesajflaviu

      I test MFC classes to download files from internet server , but how can I upload it ? Can I use the same classes / tehnique ?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • D David Crow

        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

        M Offline
        M Offline
        mesajflaviu
        wrote on last edited by
        #3

        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 !

        D 1 Reply Last reply
        0
        • M mesajflaviu

          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 !

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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

          M 1 Reply Last reply
          0
          • D David Crow

            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

            M Offline
            M Offline
            mesajflaviu
            wrote on last edited by
            #5

            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 ?

            D 1 Reply Last reply
            0
            • M mesajflaviu

              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 ?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              0
              • D David Crow

                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

                M Offline
                M Offline
                mesajflaviu
                wrote on last edited by
                #7

                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 ?

                M 1 Reply Last reply
                0
                • M mesajflaviu

                  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 ?

                  M Offline
                  M Offline
                  mesajflaviu
                  wrote on last edited by
                  #8

                  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;
                  

                  }

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups