Greetings, so I have a bit of code that was previously working fine and for no reason I can find an explanation to has stopped working. Basically I am doing a firmware file upload to a device via http. I've used this code many times in the past, even on the same test device and now it fails with a corrupt file error message from the device. Below is the relevant snip for the file upload. It's a much larger script with other parts for configuration, so I've tried to just carve out the upload here for an example.

use LWP::UserAgent(); use HTTP::CookieJar::LWP(); ## Create browser object. my $jar = HTTP::CookieJar::LWP->new; my $ua = LWP::UserAgent->new( keep_alive=>200, cookie_jar => $jar, protocols_allowed => ['http', 'https'], timeout => 60, ); my $client='xxx.xxx.xxx.xxx'; my $username='username'; my $password'password'; my $fw_file='/home/location/file.bin'; my $xsrf=auth($client, $username, $password); ##xsrf session token is +provided by separate authentication sub. my $results=upgrade($client, $fw_file); sub upgrade { ## Upload file. my ($client,$fw_file)=@_; my $res=$ua->post("http://$client/upload.cgi?xsrf=$xsrf", [ 'upfile' => ["$fw_file"], 'Submit_button' => 'Upload+Software+Image', ], Content_Type => 'form-data', ); ##Continues on to other steps from here. ##This post fails where it worked previously. }

All the documentation and examples I've found have suggested posting file uploads to http in this way and it worked for ages, I would have to assume system package updates changed the way things are working, as the device being uploaded to has not changed in any way. Any thoughts about what might be handled better in this method?


In reply to LWP::UserAgent post, file upload corruption. by FeistyLemur

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.