Click to See Complete Forum and Search --> : Problem in uploading using Curl command.


rmvinodh123
05-04-2007, 12:44 PM
I am having a problem with uploading a file to apache server using the curl command.

I have tried the -F and -T options but the file is not uploaded to the destination folder (even though file moved permanently message appears in the terminal).

The following gets displayed but the file is not uploaded to the destination folder "abc".

curl -vF "name=@cmds.zip" http://vinod/abc

* About to connect() to vinod port 80
* Trying 127.0.0.1... connected
* Connected to vinod (127.0.0.1) port 80
> POST /abc HTTP/1.1
> User-Agent: curl/7.15.1 (i386-redhat-linux-gnu) libcurl/7.15.1 OpenSSL/0.9.8a zlib/1.2.3 libidn/0.6.2
> Host: vinod
> Accept: */*
> Content-Length: 456
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------9441dbf626af
>
< HTTP/1.1 100 Continue
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 27 Jun 2007 19:03:16 GMT
< Server: Apache/2.2.0 (Fedora)
< Location: http://vinod/abc/
< Content-Length: 295
< Connection: close
< Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://vinod/abc/">here</a>.</p>
<hr>
<address>Apache/2.2.0 (Fedora) Server at vinod Port 80</address>
</body></html>
* Closing connection #0


A similar problem occurs when i use the T option.

Thanks in advance.

bwkaz
05-04-2007, 06:40 PM
(even though file moved permanently message appears in the terminal). Ah, but that's not the message that's appearing in the terminal. ;)

The message that's appearing is "301 Moved Permanently", which is different than "file moved permanently". What you're getting is an HTTP redirect: to get the request to work, you need to send it to the URL in the Location: header instead of the URL you sent it to the first time around.

In other words, you need to:

curl -vF "name=@cmds.zip" http://vinod/abc/

instead (with the trailing slash). HTTP requires the trailing slash when you're asking for (or POSTing to) a directory. Most web servers will send a 301 response if you omit the slash and your URL resolves to a directory, but it's not necessarily required (they could fail the request in some other way). The 301 response makes a normal web browser re-send the POST to the new URL, but curl doesn't do that for whatever reason. So you have to do it yourself.

rmvinodh123
05-08-2007, 05:39 PM
Thanks for the reply, i tried out what u said but i got this "Method not allowed" message , does this have anything to do with the apache server running on my comp?


[vin@vinod Books]$ curl -T cmds.txt http://vinod/abc/

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for the URL /abc/cmds.txt.</p>
<hr>
<address>Apache/2.2.0 (Fedora) Server at vinod Port 80</address>
</body></html>


[vin@vinod Books]$ curl -vF "name=@cmds.txt" http://vinod/abc/

* About to connect() to vinod port 80
* Trying 127.0.0.1... connected
* Connected to vinod (127.0.0.1) port 80
> POST /abc/ HTTP/1.1
> User-Agent: curl/7.15.1 (i386-redhat-linux-gnu) libcurl/7.15.1 OpenSSL/0.9.8a zlib/1.2.3 libidn/0.6.2
> Host: vinod
> Accept: */*
> Content-Length: 442
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------0dc6c1273c32
>
< HTTP/1.1 100 Continue
< HTTP/1.1 404 Not Found
< Date: Sat, 05 May 2007 16:55:12 GMT
< Server: Apache/2.2.0 (Fedora)
< Content-Length: 272
< Connection: close
< Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /abc/ was not found on this server.</p>
<hr>
<address>Apache/2.2.0 (Fedora) Server at vinod Port 80</address>
</body></html>
* Closing connection #0

bwkaz
05-08-2007, 07:07 PM
Um, you do have a CGI script sitting in the directory that /abc/ is ScriptAliased to, correct? And that script does allow file uploads? Because that's the only way that a POST is going to work. You can't POST a file and expect the web server to know what to do with it; the web server needs to run a CGI script that knows what to do with the file (probably save it somewhere). Perl has a fairly nice (IMO) interface to most of the CGI functionality, including POSTing files, if you don't have a script written already.

Now, if you turned on the proper options, then you might be able to use the PUT verb (instead of POST). But I don't know whether curl has support for that or not, and I don't know how to set Apache up to allow it. You might have to turn on WebDAV.

rmvinodh123
05-09-2007, 12:25 PM
"you do have a CGI script sitting in the directory that /abc/ is ScriptAliased to".

I don't understand what that means. Do i have to write a cgi script so as to enable it to save the file being posted?? I am not familiar with cgi yet, could you help me out with a sample script.

Thanks.

bwkaz
05-09-2007, 07:09 PM
It'd take me at least a few hours to write a script. You may want to try googling for (e.g.) "perl cgi file upload script" and see what you can find; I'm not sure how well that would work, but it'd be much faster than me trying to write one for you.

Or, look into the PUT verb support.

rmvinodh123
05-10-2007, 04:44 PM
I got some information about that @ http://www.sitepoint.com/article/uploading-files-cgi-perl
Now how should i use this script so as to perform the upload with curl?

bwkaz
05-10-2007, 07:17 PM
All you need is this script:

http://www.sitepoint.com/article/uploading-files-cgi-perl/2

and then you'd POST to the URL that points to the script using curl, yes.

rmvinodh123
05-11-2007, 01:30 AM
"then you'd POST to the URL that points to the script using curl"
Thanks for the reply, but i didn't understand what that means.

curl -T <file> <url>
Do i have to replace the "http://vinod/abc/" in the url?

bwkaz
05-11-2007, 06:56 PM
"then you'd POST to the URL that points to the script using curl" Apache creates (using its config file) a mapping from URL to physical file. You need to POST to the URL that corresponds to the file-upload script's physical file.

Most of the time, this mapping is really obvious (ScriptAlias in the Apache config maps a URL "directory" to a real physical one, and then every script file in the physical directory looks like a file in the URL "directory"), but it doesn't have to be.

Do i have to replace the "http://vinod/abc/" in the url? You may have to add the upload script's name to the end of the URL, though I'm not sure how curl works with upload POSTs.