Hi, Folks

I am a newbie to the Perl Programming. I'm attempting to write a Perl script that can upload a file to a web server based on the following file upload form:

<form method="post" action="/cgi-bin/luci/engineer/advanced/diagnostic +s/upgrade/"> <div class="cbi-map"> <h2><a id="content" name="content">Authorization Required</a>< +/h2> <div class="cbi-map-descr"> Please enter your username and password. </div> <fieldset class="cbi-section"><fieldset class="cbi-section-nod +e"> <div class="cbi-value"> <label class="cbi-value-title">Username</label> <div class="cbi-value-field"> <input class="cbi-input-user" type="text" name="us +ername" value="" /> </div> </div> <div class="cbi-value"> <label class="cbi-value-title">Password</label> <div class="cbi-value-field"> <input class="cbi-input-password" type="password" +name="password" /> </div> </div> </fieldset></fieldset> </div> <div> <input type="submit" value="Login" class="cbi-button cbi-butto +n-apply" /> <input type="reset" value="Clear" class="cbi-button cbi-button +-reset" /> </div> </form>

And here's my Perl code (URL, username, and password redacted):

use LWP; use HTTP::Cookies; use WWW::Mechanize; my $userAgent = LWP::UserAgent->new(); my $request = POST 'http://192.168.1.1/cgi-bin/luci/root/advanced/diag +nostics/upgrade', Content_Type => 'multipart/form-data', Content => [ +file_0 => ['upload.zip']]; $request->authorization_basic('root', '1234'); my $response = $userAgent->request($request); print $response->error_as_HTML . "\n" if $response->is_error; my $cj = HTTP::Cookies->new( autosave => 1, ignore_discard => 1 ); my $mech = WWW::Mechanize->new( cookie_jar => $cj ); $mech->get( 'http://192.168.1.1/cgi-bin/luci/root/advanced/diagnostics +/upgrade' ); if ($mech->success()) { $mech->submit_form( form_name => 'sysauth', fields => { os_usernam +e => 'root', os_password => '1234' } ); }
The output says:"There is no form named"sysauth"". Can anyone tell me how to fix this? I found another thing, when I login, the source code of form changed:
<form method="post" action="/cgi-bin/luci/;stok=4DB4115975EF48FD742227 +BAD3580034/engineer/advanced/diagnostics/upgrade" enctype="multipart/ +form-data"> <table width="100%"> <tr>&nbsp;</tr> <tr> <td width="15%" align="right">Firmware image:</td> <td width="25%" align="left"> <input type="file" size="30" name="image" /> </td> <td width="10%">&nbsp;</td> <td width="40%" align="right"> <input class="cbi-input-save" type="submit" value="Fla +sh the specified firmware file" /> </td> <td width="10%">&nbsp;</td> </tr> </table> &nbsp; </form>
A random token was generated to the URL, so maybe I need use HTTP:Cookies to keep this change, any suggestions from u, monks?

Update: I have tried another method please jump to topic:Control IE to upload file issue


In reply to Upload Issue by owenhhs007

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.