?
Solved

Better function to download file through http

Posted on 2004-09-17
3
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 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