cURL / Mailing Lists / curl-library / Single Mail


Using curl lib for files download

From: Sergei Trofimov <>
Date: Tue, 30 Dec 2008 13:53:49 +0300

Hello Everyone,

I need "file download" functionality with "pause/resume" feature for
my application. And for now Curl looks very promising for this.
So I wrote some small peace of code to see how it will work and have
some problems here.
The code is:
#include "stdafx.h"
#include <stdio.h>
#include <curl/curl.h>

size_t my_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
        return fwrite(ptr, size, nmemb, stream);

int _tmain(int argc, _TCHAR* argv[])
        CURL *curl;
        CURLcode res;
        FILE *outfile;

        curl = curl_easy_init();
        if(curl) {
                outfile = fopen("test.exe", "w");
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);
                curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
                curl_easy_setopt(curl, CURLOPT_URL, "");
                curl_easy_setopt(curl, CURLOPT_PROXY, "");
                curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
                res = curl_easy_perform(curl);
                /* always cleanup */
        return 0;

The "" is real valid URL and IE or
Firefox ask to save file if I use this URL in these browsers.
Also I'm behind the firewall and access internet thought autoproxy.
When I run this compiled source on Windows I got:

* About to connect() to proxy port 9090 (#0)
* Trying * connected
* Connected to ( port 9090 (#0)
> GET HTTP/1.1
Pragma: no-cache
Accept: */*
Proxy-Connection: Keep-Alive

< HTTP/1.1 404 Not Found
< Date: Tue, 30 Dec 2008 10:09:45 GMT
< Server: Apache/2.0.46 (Red Hat)
< Content-Length: 331
< Connection: close
< Content-Type: text/html; charset=iso-8859-1
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
110 331 110 331 0 0 623 0 --:--:-- --:--:--
--:--:-- 0* Closing connection #0

In test.exe I got the following:
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL /test.exe was not found on this server.</p>
<hr />
<address>Apache/2.0.46 (Red Hat) Server at Port 80</address>
Why I got "file not found" error if URL is valid? Can some1 tell me
what I did wrong?
P.S. I use latest 7.19.2 version of Curl lib which I downloaded from
site. This version was build with ssl and zlib support. Use WinXP SP2
OS and VS2008 as dev tool.
P.S.S. Sorry for such long mail and bad english.
Received on 2008-12-30