Solved

Better function to download file through http

Posted on 2004-09-17
3
193 Views
Last Modified: 2013-11-20
I already had a function to download file from http server.
My question is, is this function (GetFile()) good enough or there are another functions that work better (in speed)?
If there are better function, I need it.

for information, my program will download about 1000 files (size: 5 kilobytes, each file)

bool CMyProject::GetFile(const char *url, const char *filename)
{
     #define HTTPBUFLEN    512 // Size of HTTP Buffer...
     char httpbuff[HTTPBUFLEN];
     TCHAR   szCause[255];
 
     TRY
     {
          CInternetSession mysession;
          CStdioFile *remotefile = mysession.OpenURL(url,1,INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_RELOAD);
 
          CFile myfile(filename, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
            int numbytes;
 
              while (numbytes = remotefile->Read(httpbuff, HTTPBUFLEN))
                     myfile.Write(httpbuff, numbytes);
             
              mysession.Close();
              myfile.Close();
     }
 
     CATCH_ALL(error)
     {
          error->GetErrorMessage(szCause,254,NULL);
              //Out(szCause);
              return false;
     }
     END_CATCH_ALL;
 
     return true;
}
0
Comment
Question by:nk2003
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 125 total points
Comment Utility
What about

URLDownloadToFile ( NULL, "http://www.experts-exchange.com/thefile.zip", "c:\\somewhere\\thefile.zip", 0, NULL);

?

0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
Speed - the slowest bit in this procedure is likely to be your internet connection.  Would another routine actually give you any improvement?
0
 

Author Comment

by:nk2003
Comment Utility
Thanks jkr, URLDownloadToFile() is faster than my GetFile() function.
But I still don't know what's bad with my function......  Do you know why?

And one more question, how to input/set the proxy server?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now