cURL / Mailing Lists / curl-library / Single Mail

curl-library

size not being reset?

From: Dave Halbakken <YetAnotherDev_at_netscape.net>
Date: Mon, 27 Jan 2003 18:23:28 -0800

Hi,

I'm using Version 7.10.3 release of curl and MSVC6/Win32.

I am getting a CURLE_PARTIAL_FILE error code where I don't expect it.
The attached file is a distillation of a C++ program I'm working on. At
line 89 of my attached test.c, I get CURLE_PARTIAL_FILE as a return
code from curl_easy_perform. It looks as if curl retains the file size
from the previous transfer, then at line 609 of lib\ftp.c executes the
following code:

     if((-1 != conn->size) && (conn->size != *ftp->bytecountp) &&
        (conn->maxdownload != *ftp->bytecountp)) {
       failf(data, "Received only partial file: %d bytes",
*ftp->bytecountp);
       return CURLE_PARTIAL_FILE;

conn->size is non-zero, but *ftp->bytecountp is zero, so the code
returns CURLE_PARTIAL_FILE.

I wonder whether I'm misusing libcurl, or whether the conn->size should
have been reset by curl code while executing my last curl_easy_perform.
If the latter, I'd appreciate some hints as to where I might reset
conn->size.

Dave Halbakken

#include "curl.h"

size_t CurlHeaderCallback(void *aBuffer,
              size_t aMemberSize,
              size_t aMemberCount,
              void *aThisPtr)
{
  return aMemberSize * aMemberCount;
}

size_t CurlWriteCallback(void *aBuffer,
              size_t aMemberSize,
              size_t aMemberCount,
              void *aThisPtr)
{
  return aMemberSize * aMemberCount;
}

size_t CurlReadCallback(void *aBuffer,
              size_t aMemberSize,
              size_t aMemberCount,
              void *aThisPtr)
{
  return aMemberSize * aMemberCount;
}

int CurlProgressCallback(void *aThisPtr,
              double dltotal,
              double dlnow,
              double ultotal,
              double ulnow)
{
  return 0;
}

int CurlPasswdCallback(void *aThisPtr,
              const char *prompt,
              char *buffer,
              int buflen)
{
  return 0;
}

int main()
{
  CURL *theCurlHandle;
  CURLcode aCURLcode;
  struct curl_slist *theList;

  curl_global_init(CURL_GLOBAL_ALL);
  theCurlHandle = curl_easy_init();

  curl_easy_setopt(theCurlHandle, CURLOPT_NOSIGNAL, (long)1);
  curl_easy_setopt(theCurlHandle, CURLOPT_FTP_USE_EPSV, (long)0);
  curl_easy_setopt(theCurlHandle, CURLOPT_BUFFERSIZE, (long)CURL_MAX_WRITE_SIZE);
  curl_easy_setopt(theCurlHandle, CURLOPT_NOBODY, (long)1);
  curl_easy_setopt(theCurlHandle, CURLOPT_DNS_USE_GLOBAL_CACHE, (long)0);
  curl_easy_setopt(theCurlHandle, CURLOPT_TIMEOUT, (long)60);
  curl_easy_setopt(theCurlHandle, CURLOPT_WRITEFUNCTION, CurlWriteCallback);
  curl_easy_setopt(theCurlHandle, CURLOPT_WRITEDATA, 0/*this*/);
  curl_easy_setopt(theCurlHandle, CURLOPT_READFUNCTION, CurlReadCallback);
  curl_easy_setopt(theCurlHandle, CURLOPT_READDATA, 0/*this*/);
  curl_easy_setopt(theCurlHandle, CURLOPT_HEADERFUNCTION, CurlHeaderCallback);
  curl_easy_setopt(theCurlHandle, CURLOPT_WRITEHEADER, 0/*this*/);
  curl_easy_setopt(theCurlHandle, CURLOPT_PROGRESSFUNCTION, CurlProgressCallback);
  curl_easy_setopt(theCurlHandle, CURLOPT_PROGRESSDATA, 0/*this*/);
  curl_easy_setopt(theCurlHandle, CURLOPT_PASSWDFUNCTION, CurlPasswdCallback);
  curl_easy_setopt(theCurlHandle, CURLOPT_PASSWDDATA, 0/*this*/);
  curl_easy_setopt(theCurlHandle, CURLOPT_URL, "ftp://localhost");

  // open the connection
  aCURLcode = curl_easy_perform(theCurlHandle);

  // get a file
  curl_easy_setopt(theCurlHandle, CURLOPT_URL, "ftp://localhost/dhalbakken/test.exe");
  curl_easy_setopt(theCurlHandle, CURLOPT_NOBODY, (long)0);
  theList = curl_slist_append(0, "TYPE I");
  curl_easy_setopt(theCurlHandle, CURLOPT_QUOTE, theList);
  aCURLcode = curl_easy_perform(theCurlHandle);
  curl_slist_free_all(theList);
  theList = 0;

  // get the cwd
  curl_easy_setopt(theCurlHandle, CURLOPT_NOBODY, (long)1);
  curl_easy_setopt(theCurlHandle, CURLOPT_URL, "ftp://localhost");
  theList = curl_slist_append(0, "TYPE A");
  theList = curl_slist_append(theList, "PWD");
  curl_easy_setopt(theCurlHandle, CURLOPT_QUOTE, theList);
  aCURLcode = curl_easy_perform(theCurlHandle); // returns CURLE_PARTIAL_FILE
  curl_slist_free_all(theList);

  curl_easy_cleanup(theCurlHandle);
  curl_global_cleanup();

  return 0;
}

-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
Received on 2003-01-28