cURL / Mailing Lists / curl-library / Single Mail

curl-library

Problems with libcurl and C++ (error 58/60 &c.)

From: Milo Thurston <knirirr_at_gmail.com>
Date: Mon, 23 Jun 2008 12:02:06 +0100

I'm trying to write a small app. to loop through a list of files and
download them, amongst other things. The server from which the files
are being downloaded requires a self signed certificate, and I can
successfully retrieve files with the following:

curl --cert ./pass.pem https://server/file.zip -k -o file.zip

However, my code fails with errors 58 or 60. Here's the basis of it:

main()
{
  CURL *curl;
  CURLcode res;
  FILE *headerfile;
  headerfile = fopen("download_stdout.txt","w");
  curl_global_init(CURL_GLOBAL_DEFAULT);
  curl = curl_easy_init();
  //filearr = list of files to download
  //path = download location

  for (j=0;j<total_number_of_files;j++)
  {
    curl_easy_setopt(curl,CURLOPT_URL,filearr[j]);
    curl_easy_setopt(curl,CURLOPT_WRITEHEADER,headerfile);
    curl_easy_setopt(curl,CURLOPT_STDERR,headerfile);
    curl_easy_setopt(curl,CURLOPT_WRITEDATA,path);
    curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,NULL);
    while(1)
   {
      curl_easy_setopt(curl,CURLOPT_SSLCERT,keyfile);
      curl_easy_setopt(curl,CURLOPT_SSL_VERIFYHOST,0);
      res = curl_easy_perform(curl);
      if (res == 0)
      {
          printf("Successfully downloaded file %s\n",filearr[j]);
      }
      else
     {
          printf("Failed to download file %s, error %d.\n",filearr[j],res);
     }
     break;
   }
  curl_easy_cleanup(curl);
}

This is, of course, derived from the examples provided with the
distribution. Can anyone suggest what is wrong with this that might
cause the errors I have been getting?
Thanks.

-- 
"One of the greatest delusions in the world is the hope that the evils in this
world are to be cured by legislation." - Thomas B. Reed 1886
http://www.sirwilliamhope.org
Received on 2008-06-23