cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: LibCURL PUT Question...

From: Casey O'Donnell <caseyodonnell_at_hotmail.com>
Date: Thu, 27 May 2004 07:08:43 -0500

I couldn't find curl_get_info() where is that?
LibCURL Version: 7.11.1
OS/Compiler: Windows XP Pro & Visual Studio 6 -- However, the target app is
cross platform, so I'm mosting using VS6 as my initial development platform.
  I was initially developing under that system, but it makes catching STDIO
(and verbose data) problematic, so this is just a standard console app.

I'll go ahead and past code + output:

extern "C"
{
        size_t read_callback(void* ptr, size_t size, size_t nmemb, void* stream)
        {
                size_t retcode;

                retcode = fread(ptr, size, nmemb, (FILE*)stream);

                printf("*** We read %d bytes from file\n", retcode);

                return retcode;
        }
}

int main(int argc, char* argv[])
{
        printf("CurlPut Test Application:\n");
        printf("Local File:\t%s\n", argv[1]);
        printf("Remote File:\t%s\n", argv[2]);

        curl_global_init(CURL_GLOBAL_ALL);

        // Do it!
        CURL* pCurl;
        CURLcode res;

        char szUserPass[512] = "";
        strcat(szUserPass, argv[3]);
        strcat(szUserPass, ":");
        strcat(szUserPass, argv[4]);

        int iHD;
        FILE* pSrcFile;

        struct stat file_info;

        iHD = open(argv[1], O_RDONLY);
        fstat(iHD, &file_info);
        close(iHD);

        pSrcFile = fopen(argv[1], "rb");

        if(pSrcFile)
        {
                int iFileLength = file_info.st_size;
                curl_off_t offFLen = file_info.st_size;

                pCurl = curl_easy_init();

                if(pCurl)
                {
                        curl_easy_setopt(pCurl, CURLOPT_VERBOSE, TRUE);
                        curl_easy_setopt(pCurl, CURLOPT_READFUNCTION, read_callback);
                        curl_easy_setopt(pCurl, CURLOPT_UPLOAD, TRUE);
                        curl_easy_setopt(pCurl, CURLOPT_PUT, TRUE);
                        curl_easy_setopt(pCurl, CURLOPT_URL, argv[2]);
                        curl_easy_setopt(pCurl, CURLOPT_READDATA, pSrcFile);
                        curl_easy_setopt(pCurl, CURLOPT_INFILESIZE_LARGE, offFLen);
                        curl_easy_setopt(pCurl, CURLOPT_USERPWD, szUserPass);
                        curl_easy_setopt(pCurl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
                        res = curl_easy_perform(pCurl);

                        curl_easy_cleanup(pCurl);
                }

                fclose(pSrcFile);
        }

        curl_global_cleanup();

        return 0;
}

OUTPUT:

CurlPut Test Application:
Local File: C:\Documents and Settings\CODONNELL\Desktop\temp.html
Remote File: http://idisk.mac.com/codonnell/Sites/bob.html
* About to connect() to idisk.mac.com port 80
* Connected to idisk.mac.com (17.250.248.77) port 80
>PUT /codonnell/Sites/bob.html HTTP/1.1
Host: idisk.mac.com
Pragma: no-cache
Accept: */*
Content-Length: 9880
Expect: 100-continue

< HTTP/1.1 100 Continue
* Connection #0 left intact
* Closing connection #0
Press any key to continue

It's pretty much the HTTP Put example with the exception that I'm using
username and password as well. I do get a CURLE_OK return value from
curl_easy_perform(pCurl). Another thing I've noticed is that my read
call-back is never entered...as you can see from the output (also checked
with break-points).

I didn't have any trouble GET-ing, though I haven't tried from idisk.mac.com
or with a user/password. I was impressed how relatively easy it was to get
functionality like this rolled into my app so quickly.

Thanks for the help.

_________________________________________________________________
MSN Toolbar provides one-click access to Hotmail from any Web page – FREE
download! http://toolbar.msn.click-url.com/go/onm00200413ave/direct/01/
Received on 2004-05-27