Solved

Better function to download file through http

Posted on 2004-09-17
3
203 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
ID: 12085932
What about

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

?

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12086570
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
ID: 12100244
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 176
dog bark java program 15 87
changeXy challenge 13 67
JQuery serialize and unserialize 8 48
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

930 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

11 Experts available now in Live!

Get 1:1 Help Now