cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to download a zip file using http

From: <stuart_at_semag.juplo.com>
Date: Wed, 20 Nov 2013 12:04:33 -0500

 

On 2013-11-20 00:40, Mark Hessling wrote:

> It is working; all Zip
files start with PK, so you are downloading the zip file but displaying
it to stdout.
>
>> So how do i download a zip from a url?
> To capture
the output in a file have a look at the CURLOPT_WRITEFUNCTION of
curl_easy_setopt().
>
> Cheers, Mark

> okay i got a few questions
here.
 First Where does it save this file too. Second I changed my code
now and i dont get the PK thing anymore. it might not be downloading it
or s

> lockquote class="moz-cite-prefix">here
 have now. #include
<iostrea

> ;
>
> size_t write_da
 size_t size, size_t nmemb, FILE
*s

> e_t written = fwrite(ptr, size, nmemb, stream);
> return
written;
> }
>
> int main(void) {
> CURL *curl;
> FILE *fp;
> CURLcode
res;
> char *url = "http://test.com/update/testt.zip";
> char
outfilename[FILENAME_MAX] = "test.zip";
> curl = curl_easy_init();
> if
(curl) {
> fp = fopen(outfilename,"wb");
> if (fp !=NULL)
> {
> cout <<
"file openedn";
> }
> curl_easy_setopt(curl, CURLOPT_URL,
"http://test.com/update/testt.zip");
> curl_easy_setopt(curl,
CURLOPT_WRITEFUNCTION, write_data);
> curl_easy_setopt(curl,
CURLOPT_WRITEDATA, fp);
> res = curl_easy_perform(curl);
> /* always
cleanup */
> curl_easy_cleanup(curl);
> fclose(fp);
>
system("PAUSE");//so i can see output
> }
> return 0;
> }

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-11-20