cURL / Mailing Lists / curl-library / Single Mail

curl-library

Error when download file from server which have configured load balancing

From: <ianguo_at_linpus.com>
Date: Mon, 18 Aug 2008 17:23:10 +0800

Hi list,
    I am using libcurl (version:7.16.4) to design a software that can
download file from server which have configured load balancing. But I
cannot perform it when use protocol ftp.
    Firstly, I should describe the server side. There are three servers:
A, B, C. The server A is configured as load balancing dispatcher. When
client connect to A, it will dispatch B or C to response the client
according to the load of B and C.
    Client side codes as follows:
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl,CURLOPT_VERBOSE,1);
curl_easy_setopt(curl,CURLOPT_LOW_SPEED_LIMIT,LOW_SPEED);
curl_easy_setopt(curl,CURLOPT_LOW_SPEED_TIME,LOW_SPEED_TIME);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl,CURLOPT_PROGRESSFUNCTION,update_progress_bar);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);

curl_easy_setopt(curl,CURLOPT_URL,url_file);//server A
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,my_write);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,&ftpfile);

do
{
     iMaxRetry--;
     if(!access(ftpfile.filename,W_OK))
     {
     //iResumeTransfer = 1;
         if(!stat(ftpfile.filename,&file_info))
         {
             lResumeFrom = file_info.st_size;
         }
         else
             lResumeFrom = 0;
      }
      else
          lResumeFrom = 0;

      curl_easy_setopt(curl, CURLOPT_RESUME_FROM, lResumeFrom);
      res = curl_easy_perform(curl);

}while(iMaxretry > 0)

curl = curl_easy_cleanup();

   When we use http, the above codes works fine. But when use ftp,
libcurl fails. libcurl send request to server A:21, then A dispatch
B:1234 to response, but libcurl still try to connect server A:1234. It
will certainly fail, because the port 1234 of server A is forbidden to
access.

   I have read the manual of libcurl, but I cannot find a solution. Can
anybody help me to solve the problem? Thank you.

Best regards,
Ian
Received on 2008-08-18