cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to download a zip file using http

From: Mark Hessling <mark_at_rexx.org>
Date: Wed, 20 Nov 2013 15:40:38 +1000

On 20/11/13 10:18, stuart_at_semag.juplo.com wrote:
>
> I am wondering since i am a little confused on how to download a zip
> file from a url like www.example.com/test.zip? I have looked at the
> examples such as simple.c but that only returns the source of the
> page. I than tried to do something like this (idk if it would be
> better as a attachment or not).
>
> #include <stdio.h>
> #include <curl.h>
>
> int main(void)
> {
> CURL *curl;
> CURLcode res;
>
> curl = curl_easy_init();
> if(curl) {
> curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/test.zip");
>
> /* Perform the request, res will get the return code */
> res = curl_easy_perform(curl);
> /* Check for errors */
> if(res != CURLE_OK)
> fprintf(stderr, "curl_easy_perform() failed: %s\n",
> curl_easy_strerror(res));
>
> /* always cleanup */
> curl_easy_cleanup(curl);
> system("PAUSE"); //so i can read what it outputs.
> }
> return 0;
> }
>
> It returns PK?? so something is not right here and i am using this on
> c++ but i have not found a problem with c\c++.
>
>
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
>
>
>
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html

-- 
------------------------------------------------------------------------
* Mark Hessling, mark@rexx.org http://www.rexx.org/
* Author of THE, a Free XEDIT/KEDIT editor and, Rexx/SQL, Rexx/CURL, etc.
* Maintainer of Regina Rexx interpreter
* Use Rexx? join the Rexx Language Association: http://www.rexxla.org/
------------------------------------------------------------------------

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