cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: How do I post a file from command line

From: Doug McNutt <douglist_at_macnauchtan.com>
Date: Wed, 22 Apr 2009 10:57:27 -0600

At 11:01 +0100 4/22/09, David Hounsome wrote:
>I need to communicate with a piece of hardware running a webserver,
>from a linux command line.
>
>Using curl I've managed to retrieve the hardwares status stored on an
>html page and also download its current configuration in the form of a
>xml file accessable via the web server. However I'm unable to upload a
>new configuration file to it. The configuration file is normally
>uploaded via a web page form.
>
>I've found the source code on the web server that allows file upload and it is:
>
><form target="resultFrame" action="tcf" method="post"
>enctype="multipart/form-data" name="frm_download">
><input type="hidden" value="dcp" name="cgi"/>
><input type="hidden" value="set" name="method"/>
><input type="hidden" value="/" name="path"/>
><input type="hidden" value="text/html" name="content"/>
><strong>File: </strong>
><input type="file" size="45" value="File" name="localfile"/>
><input type="submit" onclick="updateStatus()" value="Upload" name="download"/>
></form>
>
>The file i wish to upload (tcf.xml) is local to where I'm running the
>linux command line from so i constructed the following curl command:
>
> curl -v -i -F localfile=@tcf.xml -F "download=Upload" http://10.90.5.70/tcf
>
>which gave me this in response
>
>* About to connect() to 10.90.5.70 port 80
>* Trying 10.90.5.70... connected
>* Connected to 10.90.5.70 (10.90.5.70) port 80
>> POST /tcf HTTP/1.1
>> User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
>> Host: 10.90.5.70
>> Accept: */*
>> Content-Length: 7114
>> Expect: 100-continue
>> Content-Type: multipart/form-data; boundary=----------------------------eb5e77766c8c
>>
>< HTTP/1.0 408 Request Timeout
>HTTP/1.0 408 Request Timeout
>< Content-type: text/html
>Content-type: text/html
>< Server :Tandberg Television Web server
>Server :Tandberg Television Web server
>
>Closing connection #0
><HTML><HEAD><TITLE>408 Request Timeout</TITLE></HEAD><BODY><H1>408
>Request Timeout</H1>Your browser did not complete it's
>request<P></BODY></HTML>
>

1) You'll almost surely need to include those "hidden" name=value pairs in your POST.

2) that onclick call to JavaScript updateStatus() is the bane of my personal existence. JavaScript can and will rearrange the entire format of a form submit request. It an also add a cookie or two with random numbers generated in a way that seems, perhaps is, designed to make automation impossible.

The LiveHTTP headers add-on for Firefox or, for a Mac, the log file from iCab will show you exactly how a browser sends out the POST. With luck you'll only have to fake the exact results in your POST. Will less luck you'll need only to scan the HTML for values to be included. With my luck you'll have to download other files that apply call-home schemes to record what you're doing and provide a secret of the day.

-- 
--> From the U S of A, the only socialist country that refuses to admit it. <--
-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ:        http://curl.haxx.se/docs/faq.html
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2009-04-22