curl-library
libcurl putting empty file on Mac OS X
Date: Tue, 16 Dec 2003 15:19:42 -0800
Hi,
I have some simple code (included below, and the same thing happens
with the httpput example) that tries to put a file onto a Windows
machine that I have running with Apache and WebDAV. This code works
just fine on Linux, and when I do a curl -T from my Mac, I can put the
file up there. However, when I run this code on my Mac, Apache's
access log says:
"PUT /test.mov HTTP/1.1" 201 268
"" 501 298
and there's an empty file on the server. I'm not sure where the extra
command is from. Running curl with --trace gives me:
== Info: About to connect() to IP_ADDRESS_HIDDEN:80
== Info: Connected to IP_ADDRESS_HIDDEN (IP_ADDRESS_HIDDEN) port 80
=> Send header, 247 bytes (0xf7)
0000: PUT /test.mov HTTP/1.1
0018: User-Agent: curl/7.10.2 (powerpc-apple-darwin7.0) libcurl/7.10.2
0058: OpenSSL/0.9.7b zlib/1.1.4
0074: Host: IP_ADDRESS_HIDDEN
008a: Pragma: no-cache
009c: Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
00de: Content-Length: 13131
and the output from the included program is:
[snowstake:inst/darwin-dbg/bin] josha% curlPutTest
DBG: About to connect() to IP_ADDRESS_HIDDEN:80
DBG: Connected to IP_ADDRESS_HIDDEN.pixar.com (IP_ADDRESS_HIDDEN) port
80
DBG: PUT /test.mov HTTP/1.1
Host: IP_ADDRESS_HIDDEN
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
DBG:
DBG: HTTP/1.1 201 Created
HTTP/1.1 201 Created
DBG: Date: Tue, 16 Dec 2003 23:13:38 GMT
Date: Tue, 16 Dec 2003 23:13:38 GMT
DBG: Server: Apache/2.0.46 (Win32) DAV/2
Server: Apache/2.0.46 (Win32) DAV/2
DBG: Location: http://IP_ADDRESS_HIDDEN/test.mov
Location: http://IP_ADDRESS_HIDDEN/test.mov
DBG: Content-Length: 268
Content-Length: 268
DBG: Content-Type: text/html; charset=ISO-8859-1
Content-Type: text/html; charset=ISO-8859-1
DBG: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>201 Created</title>
</head><body>
<h1>Created</h1>
<p>Resource /test.mov has been created.</p>
<hr />
<address>Apache/2.0.46 (Win32) DAV/2 Server at IP_ADDRESS_HIDDEN Port
80</address>
</body></html>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>201 Created</title>
</head><body>
<h1>Created</h1>
<p>Resource /test.mov has been created.</p>
<hr />
<address>Apache/2.0.46 (Win32) DAV/2 Server at IP_ADDRESS_HIDDEN Port
80</address>
</body></html>
DBG: Connection #0 left intact
res = 0
DBG: Closing connection #0
#include <iostream>
#include <curl/curl.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
int debugCallback(CURL* curl,
curl_infotype type,
char *data,
size_t size,
void* foo) {
if (type);
if (curl);
if (size);
if (foo);
std::cout<<"DBG: "<<data<<std::endl;
return 0;
}
int main() {
CURL *curl;
CURLcode res;
FILE *inFile;
char *inPath = "/public/testMovJ.mov";
char *outURL = "http://138.72.100.120/test.mov";
curl = curl_easy_init();
if (curl) {
//open for reading
inFile = fopen(inPath, "rb");
if (!inFile) {
std::cout<<"Unable to open file for reading\n"<<std::endl;
}
curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE);
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, debugCallback);
curl_easy_setopt(curl, CURLOPT_HEADER, TRUE);
//where to get from
curl_easy_setopt(curl, CURLOPT_READDATA, inFile);
//curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
//going to
curl_easy_setopt(curl, CURLOPT_URL, outURL);
//enable upload
curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE);
//use PUT
curl_easy_setopt(curl, CURLOPT_PUT, TRUE);
//size
curl_easy_setopt(curl, CURLOPT_INFILESIZE, ftell(inFile));
res = curl_easy_perform(curl);
std::cout<<"res = "<<res<<std::endl;
curl_easy_cleanup(curl);
fclose(inFile);
}
return 1;
}
Any ideas are appreciated!
Josh
--- Josh Anon Studio Tools, Pixar Animation Studios josha_at_pixar.com ------------------------------------------------------- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=clickReceived on 2003-12-17