cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-library Mailing List Archives

Using curl lib for files download

From: Sergei Trofimov <sergei.trofimov_at_gmail.com>
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_global_init(CURL_GLOBAL_ALL);
        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, "http://site.company.com/test.exe");
                curl_easy_setopt(curl, CURLOPT_PROXY, "http://autoproxy.company.com:9090");
                curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
                res = curl_easy_perform(curl);
                
                fclose(outfile);
                /* always cleanup */
                curl_easy_cleanup(curl);
        }
        return 0;
}

The "http://site.company.com/test.exe" 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 autoproxy.company.com port 9090 (#0)
* Trying 143.182.250.101... * connected
* Connected to autoproxy.company.com (143.182.250.101) port 9090 (#0)
> GET http://site.company.com/test.exe HTTP/1.1
Host: site.company.com
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:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<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
registrationcenter.intel.com Port 80</address>
</body></html>
Why I got "file not found" error if URL is valid? Can some1 tell me
what I did wrong?
thanks
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.
--Sergei
Received on 2008-12-30

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET