cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-library Archives

download an file on Mac OS X

From: Jürgen Keser <jkeser_at_computerworks.de>
Date: Mon, 11 Feb 2013 17:26:36 +0100

Hi All,

we use Mac OS X 10.8 and Xcode 4.5.2. Here we try now to create our first simple (Cocoa Application) example with the
curl-library. We will download an file with this library and place the downloaded file to a special place. Enclosed I'll send you
the code we use until now. The curl_easy_setopt functions return all true, but the file will not be downloaded.
Also the Cocoa Application will cause an crash at the end. Is there anyone out there who can help me?

Thanks for any hints.

int main(void) {
    
    curl_global_init(CURL_GLOBAL_ALL);
    
    CURL *curl;
    FILE *fp;
    CURLcode res;
    
    char *url = "http://curl.haxx.se/download/curl-7.29.0.tar.gz";

    curl = curl_easy_init();
    
    if (curl) {
        char outfilename[FILENAME_MAX] = "/OS X/ff";
        fp = fopen(outfilename,"curl-7.29.0.tar.gz");
        
        if(CURLE_OK == (res = curl_easy_setopt(curl, CURLOPT_URL, url))){
            NSAlert *alert = [[[NSAlert alloc] init] autorelease];
            [alert setMessageText:@"CURLOPT_URL OK"];
            [alert runModal];
        }
        
        if(CURLE_OK == (res = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L))){
            NSAlert *alert = [[[NSAlert alloc] init] autorelease];
            [alert setMessageText:@"CURLOPT_NOPROGRESS OK"];
            [alert runModal];
        }
        
        if(CURLE_OK == (res = curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L))){
            NSAlert *alert = [[[NSAlert alloc] init] autorelease];
            [alert setMessageText:@"CURLOPT_FOLLOWLOCATION OK"];
            [alert runModal];
        }
        
        if(CURLE_OK == (res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp))){
            NSAlert *alert = [[[NSAlert alloc] init] autorelease];
            [alert setMessageText:@"CURLOPT_WRITEDATA OK"];
            [alert runModal];
        }

        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        fclose(fp);
    }
    return 0;
}

Best regards,
Jürgen Keser

ComputerWorks GmbH
Schwarzwaldstraße 67
79539 Lörrach / Germany
Fon +49 (0)76 21 / 40 18 27
Fax +49 (0)76 21 / 40 18 18
jkeser_at_computerworks.de
http://www.computerworks.de

Geschäftsführer: Carlos Pedro Lüthy, Jörg Adrian Weber
Amtsgericht Freiburg HRB 411648
Umsatzsteuer-ID DE 142396681

Distributor für Deutschland, Schweiz und Österreich:
Vectorworks - CINEMA 4D - Trimble SketchUp - FastTrack Schedule - NisusWriter und andere.

Diese Nachricht ist nur für den Empfänger bestimmt. Sie enthält persönliche vertrauliche Informationen. Der Inhalt darf an keinen anderen außer den Empfänger weitergeleitet werden. Unbefugte Empfänger werden gebeten, diese Vertraulichkeit zu wahren und den Absender sofort über einen Übertragungsfehler zu informieren.

This message is intended for the addressee only. It contains private and confidential information. The contents are not to be disclosed to anyone other than the addressee. Unauthorized recipients are requested to comply with the above and to inform the sender immediately of any errors in transmission by replying to this message and please delete it from your computer.

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

These mail archives are generated by hypermail.

donate! Page updated January 05, 2012.
web site info

File upload with ASP.NET