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 to find if the file is transferred [modified]

how to find if the file is transferred [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
comsysadminhelptutorialquestion
2 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.
  • D Offline
    D Offline
    Dhiraj kumar Saini
    wrote on last edited by
    #1

    Hello , I am sending a gif file to the HTTP Server. Is there any way to find that the file is transfered successfully. If yes how?

    INTERNET_BUFFERS BufferIn = {0};
    DWORD dwBytesRead;
    DWORD dwBytesWritten;
    BYTE pBuffer[1024]; // Read from file in 1K chunks
    BOOL bRead, bRet;
    HANDLE hFile;

    HINTERNET hSession = InternetOpen(NULL,
                                      INTERNET\_OPEN\_TYPE\_PRECONFIG,
                                      NULL,
                                      NULL,
                                      0);
    HINTERNET hConnection = InternetConnect(hSession, 
                                            \_T("www.crmpanel.com"),  // Server
                                            INTERNET\_DEFAULT\_HTTP\_PORT,
                                            NULL,     // Username
                                            NULL,     // Password
                                            INTERNET\_SERVICE\_HTTP,
                                            0,        // Synchronous
                                            NULL);    // No Context
    
    
    
    
     BufferIn.dwStructSize = sizeof( INTERNET\_BUFFERS );
    
     HINTERNET hRequest = HttpOpenRequest(hConnection,
    										\_T("PUT"),
    										\_T("/temp"),
    										NULL,
    										NULL,
    										NULL,
    										0,
    										0);
     if (!hRequest)
     {
       //printf("Failed to open request handle: %lu\\n", GetLastError ());
    	 MessageBox(\_T("Failed to open request handle:"),NULL,MB\_OK);
       return ;
     }
    
    
    
     hFile = CreateFile (\_T("c:\\\\Image1.gif"),
    					GENERIC\_READ,
    					FILE\_SHARE\_READ,
    					NULL,
    					OPEN\_EXISTING,
    					FILE\_ATTRIBUTE\_NORMAL,
    					NULL);
    
     if (hFile == INVALID\_HANDLE\_VALUE)
     {
      	    MessageBox(\_T("Failed to open local file"),NULL,MB\_OK);
       return ;
     }
    
    
    
     BufferIn.dwBufferTotal = GetFileSize(hFile, NULL);
     MessageBox(\_T("File size is"),NULL,MB\_OK);
    
     if(!HttpSendRequestEx(hRequest, &BufferIn, NULL, HSR\_INITIATE, 0))
     {
    	 MessageBox(\_T("Error on HttpSendRequestEx"),NULL,MB\_OK);
    			       return ;
     }
    
    
     DWORD sum = 0;
     do
     {
       if  (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer),
           &dwBytesRead, NULL)))
       {
    	 MessageBox(\_T("ReadFile failed on buffer"),NULL,MB\_OK);
                 break;
       }
       if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,
           &dwBytesWritten)))
       {
    	 MessageBox(\_T
    
    D 1 Reply Last reply
    0
    • D Dhiraj kumar Saini

      Hello , I am sending a gif file to the HTTP Server. Is there any way to find that the file is transfered successfully. If yes how?

      INTERNET_BUFFERS BufferIn = {0};
      DWORD dwBytesRead;
      DWORD dwBytesWritten;
      BYTE pBuffer[1024]; // Read from file in 1K chunks
      BOOL bRead, bRet;
      HANDLE hFile;

      HINTERNET hSession = InternetOpen(NULL,
                                        INTERNET\_OPEN\_TYPE\_PRECONFIG,
                                        NULL,
                                        NULL,
                                        0);
      HINTERNET hConnection = InternetConnect(hSession, 
                                              \_T("www.crmpanel.com"),  // Server
                                              INTERNET\_DEFAULT\_HTTP\_PORT,
                                              NULL,     // Username
                                              NULL,     // Password
                                              INTERNET\_SERVICE\_HTTP,
                                              0,        // Synchronous
                                              NULL);    // No Context
      
      
      
      
       BufferIn.dwStructSize = sizeof( INTERNET\_BUFFERS );
      
       HINTERNET hRequest = HttpOpenRequest(hConnection,
      										\_T("PUT"),
      										\_T("/temp"),
      										NULL,
      										NULL,
      										NULL,
      										0,
      										0);
       if (!hRequest)
       {
         //printf("Failed to open request handle: %lu\\n", GetLastError ());
      	 MessageBox(\_T("Failed to open request handle:"),NULL,MB\_OK);
         return ;
       }
      
      
      
       hFile = CreateFile (\_T("c:\\\\Image1.gif"),
      					GENERIC\_READ,
      					FILE\_SHARE\_READ,
      					NULL,
      					OPEN\_EXISTING,
      					FILE\_ATTRIBUTE\_NORMAL,
      					NULL);
      
       if (hFile == INVALID\_HANDLE\_VALUE)
       {
        	    MessageBox(\_T("Failed to open local file"),NULL,MB\_OK);
         return ;
       }
      
      
      
       BufferIn.dwBufferTotal = GetFileSize(hFile, NULL);
       MessageBox(\_T("File size is"),NULL,MB\_OK);
      
       if(!HttpSendRequestEx(hRequest, &BufferIn, NULL, HSR\_INITIATE, 0))
       {
      	 MessageBox(\_T("Error on HttpSendRequestEx"),NULL,MB\_OK);
      			       return ;
       }
      
      
       DWORD sum = 0;
       do
       {
         if  (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer),
             &dwBytesRead, NULL)))
         {
      	 MessageBox(\_T("ReadFile failed on buffer"),NULL,MB\_OK);
                   break;
         }
         if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,
             &dwBytesWritten)))
         {
      	 MessageBox(\_T
      
      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Dhiraj kumar Saini wrote:

      Is there any way to find that the file is transfered successfully.

      If either if the if() conditions in the while() loop fail, you know the transfer was unsuccessful.

      "Love people and use things, not love things and use people." - Unknown

      "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

      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