cURL / Mailing Lists / curl-library / Single Mail

curl-library

Error when doing FTP upload via http_proxy tunnel: "Transferred a partial file"

From: Ramprasad N <ramprasad85_at_gmail.com>
Date: Tue, 1 Jul 2014 08:53:01 +0530

Hi,
The uploaded file is 34600 bytes smaller
When I tried uploading another file it was 64488 bytes smaller
This happens for all files. The last few bytes never reaches the server.
But the same files are getting uploaded well by using FileZilla client

This happens only when done via proxy
It happens irrespective of the ftp server (I've tried IIS server and
FileZilla server)

libcurl is set to pickup proxy details automatically

Here is the verbose output (I had to replace the actual server name with
---myserver.com---)

* Hostname was NOT found in DNS cache
* Trying 10.12.240.69...
  % Total % Received % Xferd Average Speed Time Time Time
 Current
                                 Dload Upload Total Spent Left
 Speed
  0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--
  0* Connected to 10.12.240.69 (10.12.240.69) port 8080 (#0)
* Establish HTTP proxy tunnel to ---myserver---.com:21
* Server auth using Basic with user 'mobily'
> CONNECT ---myserver---.com:21 HTTP/1.1
Host: ---myserver---.com:21
Proxy-Connection: Keep-Alive

< HTTP/1.1 200 Connection established
<
* Proxy replied OK to CONNECT request
< 220-FileZilla Server version 0.9.43 beta
< 220-written by Tim Kosse (tim.kosse_at_filezilla-project.org)
< 220 Please visit http://sourceforge.net/projects/filezilla/
> USER mobily
< 331 Password required for mobily
> PASS mobily123
< 230 Logged on
> PWD
  0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:--
  0< 257 "/" is current directory.
* Entry path is '/'
> EPSV
* Connect data stream passively
* ftp_perform ends with SECONDARY: 0
< 229 Entering Extended Passive Mode (|||53859|)
* Hostname was found in DNS cache
* Trying 10.12.240.69...
* Connecting to ---myserver---.com (10.12.240.69) port 8080
* Connected to 10.12.240.69 (10.12.240.69) port 8080 (#0)
* Connection to proxy confirmed
* Establish HTTP proxy tunnel to ---myserver---.com:53859
* Server auth using Basic with user 'mobily'
> CONNECT ---myserver---.com:53859 HTTP/1.1
Host: ---myserver---.com:53859
Proxy-Connection: Keep-Alive

> TYPE I
< 200 Type set to I
> STOR codec.txt
< 150 Opening data channel for file upload to server of "/codec.txt"
 97 1197k 0 0 97 1168k 0 27771 0:00:44 0:00:43 0:00:01
31307* We are completely uploaded and fine
* Remembering we are in dir ""
100 1197k 0 0 100 1197k 0 27499 0:00:44 0:00:44 --:--:--
30768< 426 Connection closed; aborted transfer of "/codec.txt"
* server did not report OK, got 426
100 1197k 0 0 100 1197k 0 27301 0:00:44 0:00:44 --:--:--
30385
* Connection #0 to host 10.12.240.69 left intact
curl_easy_perform() failed: Transferred a partial file

Here is the source code

#include <stdio.h>
#include <curl/curl.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char *argv[])
{
  CURL *curl;
  CURLcode res;
  struct stat file_info;
  double speed_upload, total_time;
  FILE *fd;

  fd = fopen("/home/ramprasad/codec.txt", "rb"); /* open file to upload */
  if(!fd) {

    return 1; /* can't continue */
  }

  /* to get the file size */
  if(fstat(fileno(fd), &file_info) != 0) {

    return 1; /* can't continue */
  }

  curl = curl_easy_init();
  if(curl) {
    /* upload to this place */
    curl_easy_setopt(curl, CURLOPT_URL,
                     "ftp://mobily:mobily123@---myserver---.com/codec.txt");

    /* tell it to "upload" to the URL */
    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);

    /* set where to read from (on Windows you need to use READFUNCTION too)
*/
    curl_easy_setopt(curl, CURLOPT_READDATA, fd);

    /* and give the size of the upload (optional) */
    curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
                     (curl_off_t)file_info.st_size);

    /* enable verbose for easier tracing */
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
    curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);

    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK) {
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    }
    else {
      /* now extract transfer info */
      curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
      curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);

      fprintf(stderr, "Speed: %.3f bytes/sec during %.3f seconds\n",
              speed_upload, total_time);

    }
    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}

I'm using libcurl version 7.83

This sample code (based on http://curl.haxx.se/libcurl/c/fileupload.html)
specifies CURLOPT_INFILESIZE_LARGE.
My actual code also fails with the same error, it uses the
CURLOPT_READFUNCTION callback to upload dynamically generated data without
specifying INFILESIZE.

I've been trying since three days to get this working......

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-07-01