cURL / Mailing Lists / curl-library / Single Mail

curl-library

Problems with FTP upload and 502 SIZE

From: John Coffey <johnco3_at_gmail.com>
Date: Tue, 26 Aug 2014 19:52:44 -0400

Hello, I wonder if someone could help me with a problem I have uploading to
a special secure FTP server. The server requires a a pair of quote side
commands prior to actually uploading the file to the FTP server, however
when it comes time to actually transfer the file (on windows 7 - built with
the latest libcurl 7.37.1), the command fails.

I have both a wireshark and debug output that seems to indicate that the
server does not support SIZE (returning a 502), I have the NO CWD option
specified and I have followed the example in the ftpupload.c - however for
some reason it appears I cannot get the file to upload. I attach the
verbose output from libCurl, and a pair of capture screenshots - one from
wireshark while attempting to upload via libCurl and anothe while
successfully uploading via another FTP client. Note that I was able to
successfully delete file from the FTP server with curl - the problem is
isolated to just uploads.

The following code how I perform the upload. Note that I never get a
callback in my CURLOPT_READFUNCTION - I have similar callbacks for
downloads and they work fine so the issue is not how I do the

// in the initialization code
CURL* pCurl = mCurlHandle.get();
curl_easy_reset(pCurl);
curl_easy_setopt(pCurl, CURLOPT_FTP_USE_EPSV, 0L);
curl_easy_setopt(pCurl, CURLOPT_FTP_USE_EPRT, 0L);
curl_easy_setopt(pCurl, CURLOPT_FTP_FILEMETHOD, CURLFTPMETHOD_NOCWD);
curl_easy_setopt(pCurl, CURLOPT_READFUNCTION, mReadFileCallback);

// at the place where the ftpupload occurs
curl_easy_setopt(pCurl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(pCurl, CURLOPT_VERBOSE, 1L);
// disable automatic directory listings
curl_easy_setopt(pCurl, CURLOPT_NOBODY, 1L);
auto fptr = fopen(localfilepath, "rb");
curl_easy_setopt(pCurl, CURLOPT_READDATA, fptr);
// size for ex is 4283148 bytes - I also tried CURLOPT_INFILESIZE with
(long)
curl_easy_setopt(pCurl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)infileSize);
struct curl_slist* slist = nullptr;
slist = curl_slist_append(slist, "SITE INTEGRITY 0x3360F2B8");
slist = curl_slist_append(slist, "SITE INTEGRITY 0x3360F2B8");
curl_easy_setopt(pCurl, CURLOPT_QUOTE, slist);
curl_easy_setopt(pCurl, CURLOPT_URL, "
ftp://192.168.193.1//cfa/cfldr/Apt_dat.dat");
fclose(fptr);
curl_easy_setopt(pCurl, CURLOPT_QUOTE, nullptr);
curl_slist_free_all(slist);
slist = nullptr;

here is the non called read callback - its a static member of a class - but
it never gets called.

/*static*/
size_t
SLDBProtocol::readFileCallback(
    char *buffer, size_t size,
    size_t nmemb, void *instream)
{
    curl_off_t nread;
    size_t retcode = fread(buffer, size, nmemb,
static_cast<FILE*>(instream));
    nread = (curl_off_t)retcode;
    //fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T
    // " bytes from file\n", nread);
    return retcode;
}

LibCurl's debug verbose output is as follows:

> SITE USERDEFINED1 0x0C6E1B82
* ftp_perform ends with SECONDARY: 0
< 200 User Defined1 will be used on next file upload only
> SITE INTEGRITY 0x3360F2B8
< 200 Integrity key will be used on next file upload only
> TYPE I
< 200 representation is now Image.
> SIZE /cfa/cfldr/Apt_dat.dat
< 502 Command not implemented.
> REST 0
< 502 Command not implemented.
* Remembering we are in dir ""
* Connection #0 to host 192.168.193.1 left intact

Here is a copy of the wireshark capture of the call, everything looks
normal except the command not implemented for the SIZE. Why is it
performing a size for a file that I am uploading? I already told it the
size via the CURLOPT_INFILESIZE_LARGE.

I also tried to upload without the quote site commands and the behavior is
the same (without the 200 responses reflecting the acceptance of the quote
site commands)

Thanks for any pointers you can give me to resolve this issue.

This is a capture from libCurl which causes problems

[image: Inline image 1]

This is a capture from a client I am trying to emulate - not sure if that
helps

[image: Inline image 2]

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html

image.png image.png
Received on 2014-08-27