cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: How do I post a file from command line

From: David Hounsome <hounsome.david_at_googlemail.com>
Date: Thu, 23 Apr 2009 08:43:22 +0100

On Wed, Apr 22, 2009 at 5:57 PM, Doug McNutt <douglist_at_macnauchtan.com> wrote:
>
> 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.

Doug,
Thanks for getting back to me so soon.

When I started work on this nightmare of a problem, the first thing I
did was to use WireShark to intercept the communication between
browser and target hardware. It was the result of this that made me
think this would be possible. I'm relativley new to this area of
programming, perhaps I misinterpreted the output. I thought using
curl I'd be able to fake the HTML post that I intercepted.

I've included the WireShark output below, both the request and the
responce (sorry, the attached xml file is quite large). Does anyone
have any ideas?

cheers

Dave

POST /tcf HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, */*
Referer: http://10.90.4.41/tcf?cgi=showdoc&tab=Save/Load&file=config.htm
Accept-Language: en-gb
Content-Type: multipart/form-data;
boundary=---------------------------7d92fd0a04d4
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;
.NET CLR 2.0.50727)
Host: 10.90.4.41
Content-Length: 7542
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: Status=http%3A//10.90.4.41/tcf%3Fcgi%3Dshow%26%24path%3D/Status

-----------------------------7d92fd0a04d4
Content-Disposition: form-data; name="cgi"

dcp
-----------------------------7d92fd0a04d4
Content-Disposition: form-data; name="method"

set
-----------------------------7d92fd0a04d4
Content-Disposition: form-data; name="path"

/
-----------------------------7d92fd0a04d4
Content-Disposition: form-data; name="content"

text/html
-----------------------------7d92fd0a04d4
Content-Disposition: form-data; name="localfile"; filename="C:\tcf.xml"
Content-Type: text/xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- TANDBERG Television DCP -->
<dcpDoc ver="1.0">
  <tcfData ver="1.0" path="/" device="SPARP3 proto"><!--
N=Name,F=Field,V=Value,S=Selection,C=Choice,D=Description,R=Record,F=Field
-->
    <Node N="root">
      <Node N="Device Info">
        <Str N="Name" V="TT1222"/>
        <Node N="Adjust Date and Time"><!-- Adjust Date and Time[5] --></Node>
        <Choice N="Time Zone" V="UTC"></Choice>
        <Table N="Alarm Filters" Size="256">
          <FieldMap F0="AlarmId" F1="Index" F2="Severity"
F3="Slot:Port:Subid Filter"/>
          <R F0="4" F1="4" F2="Clear" F3=""/>
        </Table>
        <Node N="Remote Configuration">
          <Choice N="Control Mode" V="Local"></Choice><!-- Remote
Configuration[5] -->
        </Node><!-- Device Info[4] -->
      </Node>
      <Node N="Presets">
        <Int32 N="m_preSelect" V="0"/>
        <Int32 N="m_preSave" V="0"/><!-- Presets[4] -->
      </Node>
      <Node N="Input"><!-- Input[4] --></Node>
      <Node N="Service">
        <Choice N="PSI Mode" V="DVB"></Choice>
        <Int32 N="Delay ms" V="40"/>
        <Node N="Data">
          <Choice N="Mode" V="Off"></Choice>
          <Int32 N="Aux PID" V="16"/>
          <Choice N="Profile" V="Streamed"></Choice>
          <Choice N="Output Format" V="Bin"></Choice>
          <Choice N="Buffering" V="Flow"></Choice>
          <Choice N="Baud Rate" V="115200"></Choice>
          <Int32 N="Data Bits" V="8"/>
          <Choice N="Stop Bits" V="1.0"></Choice>
          <Choice N="Parity" V="None"></Choice><!-- Data[5] -->
        </Node>
        <Int32 N="TV Service ID" V="18"/>
        <Choice N="Hunt Mode" V="Off"></Choice>
        <Node N="TV Service PIDs">
          <Int32 N="PCR" V="8190"/>
          <Int32 N="Video" V="100"/>
          <Int32 N="Audio 1" V="100"/>
          <Int32 N="TTXT" V="16"/>
          <Int32 N="TTXT Subt" V="16"/>
          <Int32 N="EBU Page" V="100"/>
          <Int32 N="DVB Subt" V="16"/>
          <Int32 N="DVB Page" V="0"/>
          <Int32 N="DVB APage" V="0"/>
          <Int32 N="VPS" V="16"/>
          <Int32 N="WSS" V="16"/>
          <Int32 N="Closed Cap" V="16"/><!-- TV Service PIDs[5] -->
        </Node>
        <Node N="Teletext - Subtitles">
          <Choice N="Ttx PTS Sync" V="On"></Choice>
          <Choice N="Teletext#1" V="On"></Choice>
          <Choice N="Teletext Src" V="TTXT"></Choice>
          <Str N="TTXT Lang" V="eng"/>
          <Choice N="Teletext Subt" V="On"></Choice>
          <Str N="EBU Subt Lang" V="eng"/><!-- Teletext - Subtitles[5] -->
        </Node>
        <Node N="DVB - Subtitles">
          <Choice N="DVB Subt#1" V="Off"></Choice>
          <Str N="DVB Subt Lang" V="eng"/>
          <Choice N="DVB Pref" V="Norm Any"></Choice><!-- DVB - Subtitles[5] -->
        </Node>
        <Node N="Service Cycling">
          <Choice N="Serv Cyc" V="Off"></Choice>
          <Int32 N="Timeout sec" V="10"/>
          <Choice N="OSD" V="Off"></Choice><!-- Service Cycling[5] -->
        </Node>
        <Node N="Video Advanced">
          <Choice N="Video625Fmt" V="PAL"></Choice>
          <Choice N="VPS" V="Off"></Choice>
          <Choice N="WSS" V="MPEG-video"></Choice>
          <Choice N="Video625TestLines" V="17,18"></Choice>
          <Choice N="FrameFormat" V="Off"></Choice>
          <Choice N="FrameConv" V="4/3PS"></Choice>
          <Choice N="Sinxx" V="Off"></Choice>
          <Choice N="OSD Pri" V="+EBU -DVB"></Choice>
          <Choice N="video525Fmt" V="NTSC"></Choice>
          <Choice N="Closed Cap" V="Off"></Choice>
          <Choice N="Video525TestLines" V="On"></Choice>
          <Choice N="Pedestal" V="On"></Choice>
          <Choice N="GCR" V="Off"></Choice>
          <Choice N="Line Standard" V="525"></Choice>
          <Choice N="Stop Mode" V="Black"></Choice>
          <Choice N="Master OSD" V="On"></Choice><!-- Video Advanced[5] -->
        </Node>
        <Str N="Aud1 Lang" V="eng"/>
        <Node N="Audio 1 Advanced">
          <Int32 N="Op Level" V="0.0"/>
          <Choice N="Modulator" V="Stereo"></Choice>
          <Choice N="Dig Audio" V="Linear"></Choice><!-- Audio 1 Advanced[5] -->
        </Node>
        <Int32 N="AUDIO2 Service ID" V="1"/>
        <Int32 N="Audio 2" V="101"/>
        <Choice N="Track Audio 1" V="Off"></Choice>
        <Str N="Aud2 Lang" V="eng"/>
        <Node N="Audio 2 Advanced">
          <Int32 N="Op Level" V="0.0"/>
          <Choice N="Modulator" V="Stereo"></Choice>
          <Choice N="Dig Audio" V="Linear"></Choice><!-- Audio 2 Advanced[5] -->
        </Node><!-- Service[4] -->
      </Node>
      <Node N="Conditional Access">
        <Choice N="CA Mode" V="Standard"></Choice>
        <Choice N="Mode#1" V="BISS 1"></Choice>
        <Choice N="Mode#2" V="BISS 1"></Choice>
        <Choice N="PMT Mode" V="1PMT(PID)"></Choice><!-- Conditional
Access[4] -->
      </Node>
      <Node N="Output">
        <Choice N="Output" V="Descramble"></Choice>
        <Choice N="ASISDI Out 1" V="SDI"></Choice>
        <Choice N="ASISDI Out 2" V="SDI"></Choice>
        <Choice N="Emb Audio Group" V="1"></Choice>
        <Choice N="Emb Audios" V="One&amp;Two"></Choice>
        <Bool N="No Input Lock#2" V="False"></Bool>
        <Bool N="Video Error#2" V="False"></Bool>
        <Bool N="Audio 1 Error#2" V="False"></Bool>
        <Bool N="Audio 2 Error#2" V="False"></Bool>
        <Bool N="Data Error#2" V="False"></Bool>
        <Bool N="No Input Lock#3" V="False"></Bool>
        <Bool N="Video Error#3" V="False"></Bool>
        <Bool N="Audio 1 Error#3" V="False"></Bool>
        <Bool N="Audio 2 Error#3" V="False"></Bool>
        <Bool N="Data Error#3" V="False"></Bool>
        <Bool N="No Input Lock#4" V="False"></Bool>
        <Bool N="Video Error#4" V="False"></Bool>
        <Bool N="Audio 1 Error#4" V="False"></Bool>
        <Bool N="Audio 2 Error#4" V="False"></Bool>
        <Bool N="Data Error#4" V="False"></Bool>
        <Bool N="No Input Lock#5" V="False"></Bool>
        <Bool N="Video Error#5" V="False"></Bool>
        <Bool N="Audio 1 Error#5" V="False"></Bool>
        <Bool N="Audio 2 Error#5" V="False"></Bool>
        <Bool N="Data Error#5" V="False"></Bool>
        <Bool N="No Input Lock#6" V="False"></Bool>
        <Bool N="Video Error#6" V="False"></Bool>
        <Bool N="Audio 1 Error#6" V="False"></Bool>
        <Bool N="Audio 2 Error#6" V="False"></Bool>
        <Bool N="Data Error#6" V="False"></Bool><!-- Output[4] -->
      </Node>
      <Choice N="Baud Rate" V="115200"></Choice>
      <Int32 N="Data Bits" V="8"/>
      <Choice N="Stop Bits" V="1.0"></Choice>
      <Choice N="Parity" V="None"></Choice>
      <Choice N="Flow Control" V="None"></Choice>
      <Choice N="Menu Lock" V="Off"></Choice><!-- root[3] -->
    </Node>
  </tcfData>
  <dcpStatus value="0" text="Success"></dcpStatus>
</dcpDoc>
-----------------------------7d92fd0a04d4
Content-Disposition: form-data; name="download"

Upload
-----------------------------7d92fd0a04d4--
HTTP/1.0 200 OK
Content-type: text/html
Server :Tandberg Television Web server

<?xml version="1.0" encoding="UTF-8"?>
<!-- TANDBERG Television DCP -->
<dcpDoc ver="1.0"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>DCP status</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" CONTENT="no-cache">
<link rel="stylesheet" href="tcf?cgi=url&file=XPOstyles.css" type="text/css">
<script language="JavaScript1.2" src="tcf?cgi=url&file=mouse.js"></script>
<script language="Javascript" src="tcf?cgi=url&file=tcheck.js"></script>
<script language="JavaScript" src="tcf?cgi=url&file=TCFparam.js"></script>
<script language="JavaScript" src="tcf?cgi=url&file=XPObase.js"></script>
<script language="JavaScript" src="tcf?cgi=url&file=XPOform.js"></script>
<script language="JavaScript" src="tcf?cgi=url&file=XPOobjects.js"></script>
</head>
<body>
<style type="text/css">
body {margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0px;}
</style><script language="JavaScript">
 function clearResult()
    {
       self.location.href = 'tcf?cgi=emptyresult';
    }
</script>
<table class="result" width="100%" border="0">
<tr class="head">
<td class="ok" valign="middle" noWrap colspan="2">
<p>Result: SUCCESS</p></td>
</tr>
<tr class="subtitle">
<td>
<p>Type</p>
</td>
<td>
<p>Description</p>
</td>
</tr>
<tr class="alt1">
<td>
<p class="note">Note</p>
</td>
<td>
<p>Transaction performed (6863 bytes received)</p>
</td>
</tr>
</table>
</body>
</html>
</dcpDoc>
-------------------------------------------------------------------
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-23