curl-library
How to download multiple files?
Date: Wed, 12 Dec 2007 00:17:25 +0100
Hello,
Currently I use curl to download files with this functions:
WebGet::WebGet ()
{
curl_global_init(CURL_GLOBAL_ALL);
/* init the curl session */
curl_handle = curl_easy_init();
}
WebGet::~WebGet ()
{
/* cleanup curl stuff */
curl_easy_cleanup(curl_handle);
}
long WebGet::urlToFile (const string &url, const string &filename)
{
FILE *file;
/* specify URL to get */
curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str ());
/* send all data to this function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION,
writeFileCallback);
/* open the files */
file = fopen(filename.c_str (), "w");
if (file == NULL)
{
curl_easy_cleanup(curl_handle);
return -1;
}
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) file);
/* some servers don't like requests that are made without a user-agent
field, so we provide one */
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
/* get it! */
curl_easy_perform(curl_handle);
long httpResponse;
curl_easy_getinfo( curl_handle , CURLINFO_HTTP_CODE , &httpResponse );
fclose (file);
return httpResponse;
}
My current solution is to run urlToFile() in a loop with multiple
files. I would like to download multiple files at the same time. So my
question is how to do that?
Before I ask many stupid question perhaps you could sketch me how to
design an application that is able to download multiple files at the
same time.
regards
Andreas
Received on 2007-12-12