curl / Mailing Lists / curl-library / Single Mail

curl-library

CURLINFO_CONTENT_LENGTH_DOWNLOAD can't get remote file in mips-linux

From: ºÚ°µ¹ââ via curl-library <curl-library_at_cool.haxx.se>
Date: Wed, 1 Nov 2017 14:56:41 +0800

Hi all:
    I want to use libcurl to to make ftp upload and resume function. I have to get remote file in ftp server to realize resume function. I used
ftpgetinfo.c to test. However it works in x86 pc, not work ini mips-linux. the CURLINFO_CONTENT_LENGTH_DOWNLOAD always return 0 which
mean the remote file size is zero.
1. The fllowing is the code:
long file_easy_getfilesize(const char *url, const char *username, const char *passward)
{
    CURL *curl;
    CURLcode res;
    double filesize = 0.0;
    curl = curl_easy_init();
    if (NULL == curl) {
        return CURLE_OUT_OF_MEMORY;
    }
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_USERNAME , username);
    curl_easy_setopt(curl, CURLOPT_PASSWORD , passward);


    curl_easy_setopt(curl, CURLOPT_NOBODY, 1L) ;
    curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, throw_away);
    curl_easy_setopt(curl, CURLOPT_HEADER, 0L);


    if (curl_easy_perform(curl) == CURLE_OK) {
        res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
                              &filesize);
        if (res == CURLE_OK) {
            if (filesize > 0.0) {
                printf("remote filesize : %0.0f bytes\n", filesize);
            } else {
                filesize = 0;
            }
        } else {
            filesize = 0;
        }


    }
    curl_easy_cleanup(curl);
    return filesize;
}

2.And I dig into libcurl. The function ftp_state_size_resp in ftp.c
  filesize = (ftpcode == 213)?curlx_strtoofft(buf+4, NULL, 0):-1;
Here filesize is ok.
But when I use CURLINFO_CONTENT_LENGTH_DOWNLOAD to get it. i't zero.
3.dig into getinfo_double in getinfo.c
  case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
    *param_doublep = (data->progress.flags & PGRS_DL_SIZE_KNOWN)?
      (double)data->progress.size_dl:-1;
    break

Here *param_doublep is zero.
4. I think data->progress.size value is given by Curl_pgrsSetDownloadSize in functionftp_state_size_resp ¡£
  if(instate == FTP_SIZE) {
#ifdef CURL_FTP_HTTPSTYLE_HEAD
    if(-1 != filesize) {
      snprintf(buf, sizeof(data->state.buffer),
               "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", filesize);
      result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);
      if(result)
        return result;
    }
#endif
    Curl_pgrsSetDownloadSize(data, filesize);

However Curl_client_write get CURLE_RECV_ERROR, and return¡£
5. I dig into function Curl_client_write in sendf.c It return here
 if(data->req.keepon & KEEP_RECV_PAUSE) {
    size_t newlen;
    char *newptr;
    if(type != data->state.tempwritetype)
      /* major internal confusion */
      return CURLE_RECV_ERROR;



Why is KEEP_RECV_PAUSE ?

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-11-01