nk2003
asked on
Better function to download file through http
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,IN TERNET_FLA G_TRANSFER _BINARY|IN TERNET_FLA G_RELOAD);
CFile myfile(filename, CFile::modeCreate|CFile::m odeWrite|C File::type Binary);
int numbytes;
while (numbytes = remotefile->Read(httpbuff, HTTPBUFLEN))
myfile.Write(httpbuff, numbytes);
mysession.Close();
myfile.Close();
}
CATCH_ALL(error)
{
error->GetErrorMessage(szC ause,254,N ULL);
//Out(szCause);
return false;
}
END_CATCH_ALL;
return true;
}
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,IN
CFile myfile(filename, CFile::modeCreate|CFile::m
int numbytes;
while (numbytes = remotefile->Read(httpbuff,
myfile.Write(httpbuff, numbytes);
mysession.Close();
myfile.Close();
}
CATCH_ALL(error)
{
error->GetErrorMessage(szC
//Out(szCause);
return false;
}
END_CATCH_ALL;
return true;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Speed - the slowest bit in this procedure is likely to be your internet connection. Would another routine actually give you any improvement?
ASKER
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?
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?