cURL / Mailing Lists / curl-library / Single Mail

curl-library

Downloading a file through HTTP proxy gives incorrect progress data when used CURLOPT_PROGRESSFUNCTION

From: manish <manishagg22_at_gmail.com>
Date: Mon, 24 Oct 2016 09:38:21 -0600

Hi,

I am using CURLOPT_PROGRESSFUNCTION to log the progress of file download.
When I try to download a file through a FTP server without any proxy, I am
getting correct progress data through "dltotal" and "dlnow" variables used
in callback function. However, if I use HTTP proxy to download a file from
the FTP server, I am getting incorrect progress data. dltotal is always
coming as "0", however dlnow is showing correct value.

Also a side issue is that, when I download a file through HTTP proxy, it
adds carriage return character at the end of every line.

Could someone let me know the root cause of this issue? Thanks in Advance

Following are the CURL options, callback method, used to log the download
progress.
============

 //following three options will help curl to dump the progress of the
download
 curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, logDownloadProgress);
 curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, theFileName.c_str());
//theFileName is the "abc.xml" here
 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);

//This function is as callback function to CURLOPT_PROGRESSFUNCTION option
setup for libcurl
static int logDownloadProgress(void *p, double dltotal, double dlnow,
double ultotal, double ulnow)
{
        char *str = (char *)p;

        double percentageDownload = (dlnow / dltotal) * 100.0;

       debug_log << "Download status of " << str
                        << " : Downloaded " << dlnow << " bytes out of " <<
dltotal << " bytes | " << percentageDownload << " % complete";

        return 0;
}
=========

Following are the logs against both case, with HTTP proxy and with no proxy.

Case 1 ; Without HTTP Proxy

Downloading file abc.xml using CURL with below options:
CURLOPT_CONNECTTIMEOUT : 10L
CURLOPT_SSL_VERIFYPEER : false
CURLOPT_USERNAME : user123
CURLOPT_PASSWORD : **********
CURLOPT_URL : ftp://x.x.x.x/abc.xml
CURLOPT_NOPROXY : *

[debug]: 1 try CURL command to download file
[debug]: About to connect() to x.x.x.x port 21 (#0)
[debug]: Trying x.x.x.x...
[debug]: connected
[debug]: Connected to x.x.x.x (x.x.x.x) port 21 (#0)
[debug]: Connect data stream passively
[debug]: Trying x.x.x.x...
[debug]: connected
[debug]: Connecting to x.x.x.x (x.x.x.x) port 51249
[debug]: Maxdownload = -1
[debug]: Getting file with size: 21221
[debug]: Download status of abc.xml : Downloaded 16384 bytes out of 21221
bytes | 77.2065 % complete
[debug]: Download status of abc.xml : Downloaded 21221 bytes out of 21221
bytes | 100 % complete
[debug]: Connection #0 to host x.x.x.x left intact
[debug]: CURL command is successful

Case 2 With HTTP Proxy

Downloading file abc.xml using CURL with below options:
CURLOPT_CONNECTTIMEOUT : 10L
CURLOPT_SSL_VERIFYPEER : false
CURLOPT_USERNAME : user123
CURLOPT_PASSWORD : **********
CURLOPT_URL : ftp://x.x.x.x/abc.xml
CURLOPT_PROXYTYPE : CURLOPT_PROXY_HTTP
CURLOPT_PROXY : y.y.y.y
CURLOPT_PROXYPORT : 3128

[debug]: 1 try CURL command to download file
[debug]: About to connect() to proxy y.y.y.y port 3128 (#0)
[debug]: Trying y.y.y.y...
[debug]: connected
[debug]: Connected to y.y.y.y (y.y.y.y) port 3128 (#0)
[debug]: Server auth using Basic with user 'User123'
[debug]: Download status of abc.xml : Downloaded 0 bytes out of 0 bytes |
-nan % complete
[debug]: HTTP 1.0, assume close after body
[debug]: Download status of abc.xml : Downloaded 6992 bytes out of 0 bytes
| inf % complete
[debug]: Download status of abc.xml : Downloaded 20480 bytes out of 0 bytes
| inf % complete
[debug]: Download status of abc.xml : Downloaded 21633 bytes out of 0 bytes
| inf % complete
[debug]: Closing connection #0
[debug]: CURL command is successful

-- 
Thanks and Regards,
Manish Agarwal

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-10-24