cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: uploaded unaligned file size

From: Mark Lively <mongothegeek_at_gmail.com>
Date: Mon, 11 Apr 2011 08:35:19 -0400

On Sun, Apr 10, 2011 at 1:28 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Sat, 9 Apr 2011, Mark Lively wrote:
>
>>> And you're _sure_ you tell libcurl the correct size before the transfer
>>> is
>>> started?
>>>
>> I using curl_easy_connect and not supplying a size.  I run the same
>> program on the same file on different machines, connecting to the same host
>> and I am getting different results which is frustrating.
>>
>> Something odd I noticed about the expected sizes.  The first one is 60
>> then 121, 182 etc.  incrementing by 61.
>
> So, can you please write up a small example that can repeat this problem and
> show us? It sounds really odd and I can't explain why libcurl to act like
> that, but perhaps I'm missing something that a full example would reveal...
>
Since I am working on Macs I wrapped libcurl with a cocoa object.

- (id) initWithUser:(NSString *) aUserName pass: (NSString *)
aPassWord host: (NSString *)aHostName dir: (NSString *) aDirName
textMode:(BOOL)asText{
    if (self = [super init]){
        userName = [aUserName copy];
        passWord = [aPassWord copy];
        hostName = [aHostName copy];
        dirName = [aDirName copy];
        curlHandle = curl_easy_init();
        curl_easy_setopt(curlHandle, CURLOPT_UPLOAD, TRUE);
        curl_easy_setopt(curlHandle, CURLOPT_FTP_RESPONSE_TIMEOUT, 25);
        curl_easy_setopt(curlHandle, CURLOPT_FORBID_REUSE, TRUE);
//fixes problem with server attempting to reset dir.
        curl_easy_setopt(curlHandle, CURLOPT_TRANSFERTEXT, asText);
    }
    return self;
}

and the send...

- (NSString *) sendFile: (NSString *) aFile{

    CURLcode anErr;
    FILE * filePtr;
    const char * cFile = [aFile cString];
    curl_easy_setopt(curlHandle, CURLOPT_USERPWD, [[NSString
stringWithFormat:@"%@:%@",userName,passWord] UTF8String]);
    NSString * verURL = [NSString
stringWithFormat:@"ftp://%@/%@/%@",hostName, dirName,[aFile
lastPathComponent]];

    filePtr = fopen (cFile, "r+");

    curl_easy_setopt(curlHandle, CURLOPT_URL, [verURL cString]);
    curl_easy_setopt(curlHandle, CURLOPT_READDATA, filePtr);
// curl_easy_setopt(curlHandle, CURLOPT_VERBOSE, YES);

    anErr = curl_easy_perform(curlHandle);

    fclose (filePtr);

    if (anErr) return [NSString stringWithFormat:@"Error in sendFile:
%d,file: %@ host: %@", anErr, aFile, hostName];
    return NULL;
}

Thank you again for your help on this. It's frustrating to me that
identical systems either work or don't work.

-Mark

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-04-11