0

(I am under windows) I am trying to download a zip file located at a given url as follows :

CURL *curl;
FILE *fp;
CURLcode res;
char *url = "https://www.markit.com/news/InterestRates_USD_20090102.zip";
char outfilename[FILENAME_MAX] = "C:\\InterestRates_USD_20090102.zip";
curl_version_info_data * vinfo = curl_version_info(CURLVERSION_NOW);
if (vinfo->features & CURL_VERSION_SSL)
{
    printf("CURL: SSL enabled\n");
}
else {
    printf("CURL: SSL not enabled\n");
}
curl = curl_easy_init();
if (curl)
{
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); //Prevent "longjmp causes uninitialized stack frame" bug
    fp = fopen(outfilename, "wb");
    int errnum = 0;
    if (nullptr == fp)
    {
        errnum = errno;
        fprintf(stderr, "Value of errno: %d\n", errno);
        perror("Error printed by perror");
        fprintf(stderr, "Error opening file: %s\n", strerror(errnum));
    }
    curl_easy_setopt(curl, CURLOPT_CAINFO, "./ca-bundle.crt");
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
}

A file C:\\InterestRates_USD_20090102.zip appears indeed, but it is a directory named InterestRates_USD_20090102.zip, not a zip file.

I don't think the problem is the zip format but rather the https url (I of course download manually the file with no problem) as res shows CURLE_UNSUPPORTED_PROTOCOL at debug. I indeed tried a lot of file format without https and had no problem, whereas any file format with https gives me the CURLE_UNSUPPORTED_PROTOCOL at debug ...

I found this page :

Using libcurl & SSL

but was unable to adapt, as inspincting the security details of the page (under chrome --> developer option --> security) yielded to an uncompatible certificate (not of the crt format)

Note that I have this problem whether I used "DLL" or "DLL Windows SSPI - DLL WinIDN", the latter including windows sll, see here : Curl 7.43.0 won't build in MSVC 2013

Community
  • 1
  • 1
Olórin
  • 3,367
  • 2
  • 22
  • 42
  • 1) Does some other part of your program create the directory? 2) Did you check whether fopen failed? – user253751 Apr 28 '17 at 11:21
  • 1) No. 2) Yes but forgot to put it in the code. I never pass inside the `if` scope but at debug `fp` shows `fp = 0x006a22d8 {_Placeholder=0x00000000 }` – Olórin Apr 28 '17 at 11:37
  • Well, `fopen` does not create a directory. `fopen` *never* creates a directory. If you pause the program after calling `fopen` it should be a file. – user253751 Apr 28 '17 at 22:17

0 Answers0