Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Better function to download file through http

Posted on 2004-09-17
3
Medium Priority
?
247 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 45

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 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