cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Problem downloading using text transfer mode

From: Abel Alonso <abelalon_at_gmail.com>
Date: Tue, 24 Jun 2008 13:01:25 +0200

The code I use to upload and download files:

//Download Code

CURL *curl;
curl = curl_easy_init();

curl_easy_setopt( curl, CURLOPT_FTP_USE_EPSV, 0 );

curl_easy_setopt(curl, CURLOPT_URL,);

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &fileWrite);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
curl_easy_setopt( curl, CURLOPT_TRANSFERTEXT, 1 );
curl_easy_setopt( curl, CURLOPT_CRLF, 1 );

curl_easy_perform(curl);

// Upload Code
CURL *curl;
curl = curl_easy_init();

curl_easy_setopt( curl, CURLOPT_FTP_USE_EPSV, 0 );
curl_easy_setopt(curl, CURLOPT_POSTQUOTE, NULL);
curl_easy_setopt(curl, CURLOPT_FTPLISTONLY, 0);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_URL, "ftp://user:pass@server:22/file.txt" );
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &chunky);

curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE);

curl_easy_setopt( curl, CURLOPT_TRANSFERTEXT, 1 );
curl_easy_setopt( curl, CURLOPT_CRLF, 1 );

// Open the file
ff.Open(job->localUrl.GetData(), wxT("rb"));

curl_easy_setopt(curl, CURLOPT_READDATA, ff.fp());
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) ff.Length());

 curl_easy_perform(curl);
// Close the file
ff.Close();

//Callbacks
int fileWrite ( void *buffer, size_t size, size_t nmemb, void *stream )
{
    // Just writes the data in a file
    // No curl code here
}

size_t FtpWorkerThread::WriteMemoryCallback ( void *ptr, size_t size, size_t
nmemb, void *data )
{
  //Just writes data in a memory space indicated by the parameter data
  // No curl code here
}

2008/6/23 Abel Alonso <abelalon_at_gmail.com>:

>
>
> 2008/6/23 Daniel Stenberg <daniel_at_haxx.se>:
>
>> On Mon, 23 Jun 2008, Abel Alonso wrote:
>>
>> I have in my local Windows machine a file with the following data:
>>>
>>> 1234567890
>>> 1234
>>>
>>
>> How are these lines separated? CRLF ?
>
>
> Yep, CRLF
>
>>
>>
>> I upload that file
>>>
>>
>> Upload how? Using what protocol?
>>
>
> FTP
>
>
>> to a Linux machine using the text transfer mode and with
>>> CURLOPT_TRANSFERTEXT and CURLOPT_CRLF enabled. When I download this file
>>> what I get is the following:
>>>
>>> 1234567890
>>> 123
>>>
>>
>> Using what line endings?
>
>
> I receive the file using CRLF line endings
>
>
>>
>>
>> This is one character less than the original file. It's just one
>>> character because I onlu have a line ending, if I would have 2 line endings
>>> I would retrieve the file with 2 characters less.
>>>
>>
>> Can you please provide a full source code to a small application that
>> repeats the problem?
>
>
> I'll send it to you tomorrow :)
>
> Thank you so much!
>
>
Received on 2008-06-24