[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

uploading files to an existing cgi script

I'm in stuck by uploading a simple file to a https site, this is what i have:

use LWP::UserAgent;
my $uri = 'https://......../to-users.pl?FILE=%2filest&LANG=en&FUNC=Upload';
my $ua = LWP::UserAgent->new;
$ua->agent("PERL LWP");
my $req = HTTP::Request->new( GET => $uri );
$req->authorization_basic('user', 'pass');
my $res = $ua->request( $req );

if ( $res->is_success ) {
    print $res->as_string;
}

Note: Authentication is not the problem at this point, i'm using this ssl mods from: http://theoryx5.uwinnipeg.ca/ppms/Crypt-SSLeay.ppd

print $res->as_string; shows:
----------------------------------
<form method="POST" action="https://............../to-users.pl" enctype="multipart/form-data">
<input type="hidden" name="DIR" value="/....">
<input type="hidden" name="FUNC" value="UPLOAD2">
<input type="hidden" name="LANG" value="en">
<table border="0">
        <tr>
                <td bgcolor="#CCCCCC"><b>&nbsp;File to upload:&nbsp;</b></td>
                <td><input type="file" name="FILE" size="40"></td>
        </tr>
        <tr>
                <td bgcolor="#CCCCCC"><b>&nbsp;If exists:&nbsp;</b></td>
                <td><input type="checkbox" name="OVR" value="ON"> overwrite</td>
        </tr>
        <tr>
                <td bgcolor="#CCCCCC"><b>&nbsp;Action:&nbsp;</b></td>
                <td><input type="submit" value="Submit"><input type="button" value="Cancel" onclick="location.href='https://.......
/cgi-bin/users/to-users.pl?LANG=en';"></td>
        </tr>
</table>
</form>
----------------------------------

Any help how i could set the submit with the filename and the overwrite chkbox would be appreciatet.

Thx

Matt

0
MKrauss
Asked:
MKrauss
  • 2
  • 2
1 Solution
 
rj2Commented:
use HTTP::Request::Common;
use LWP::UserAgent;

$filename='d:/temp/file.txt';
my $ua = LWP::UserAgent->new();
my $response = $ua->request(POST 'https://uid:pwd@www.somewhere.com/cgi-bin/upload.pl',
       Content_Type => 'form-data',
       Content      => [ FILE   => ["$filename"],                  
                       ] );
if ($response->is_success) {
     print "Post ok\n";
} else {
     print "Post failed: ",$response->code,"\n";
}      
0
 
MKraussAuthor Commented:
thx,
at least i get a Post OK (200) but the file is not uploaded to the correct path, at least i dont
see it in this web file manager, i think i need to set the hidden types "DIR" value="/..... can i do
this somehow ?
0
 
rj2Commented:
Try like below, set $remotedir to correct value.

use HTTP::Request::Common;
use LWP::UserAgent;

$filename='d:/temp/file.txt';
$remotedir='/usr/home/remotedir';
my $ua = LWP::UserAgent->new();
my $response = $ua->request(POST 'https://uid:pwd@www.somewhere.com/cgi-bin/upload.pl',
       Content_Type => 'form-data',
       Content      => [ FILE   => ["$filename"],                
                       DIR  => "$remotedir",
                       FUNC  => "UPLOAD2",
                       LANG  => "en",
                       ] );
if ($response->is_success) {
     print "Post ok\n";
} else {
     print "Post failed: ",$response->code,"\n";
}    
0
 
MKraussAuthor Commented:
rj2,
after i placed this into productive i noticed a problem with large files,  perl doesnt respond until i abort it
and the files got uploaded fine (?). Is there a way to fix that ?
I can open a new question for this if you want to.
Thanks ....
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now