|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Perl script : login + upload file
I want to write a perl script which will login in a site and then it will use its upload form to upload a file. Could someone give me some help because I can't figure it out from google?
This is the login form Code:
<form name="form1" method="POST" action="login.php"><div align="center">
<table width="556" border="0">
<tr>
<td><div align="right">username</div></td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td><div align="right">password</div></td>
<td><input name="password" type="password" id="password"></td>
</tr>
</table>
</div>
<p align="center">
<input type="submit" name="Submit2" value="submit">
</p>
</form>
and this is the upload form Code:
<form action="upload.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <p align="center"> </p> <p align="center"> <input type="file" name="userfile"/> </p> <p align="center"> <input name="submit" type="submit" value="upload"/> </p> </form> |
|
#2
|
||||
|
||||
|
Why not use php instead of perl? There's many examples in both Perl and PHP, what have you tried searching for ...?
__________________
--Ax without exception, there is no rule ... The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones ![]() 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. -- Jamie Zawinski Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ... |
|
#3
|
|||
|
|||
|
Quote:
Because from the search that I have made perl sounded good for the job. I have found some info and I wrote this script Code:
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request::Common;
# Prepare request.
my $ua = new LWP::UserAgent;
my $req = new HTTP::Request(POST => 'http://www.site.com/login.php');
$req->authorization_basic("my_username", "my_password");
print $req->as_string();
$res = $ua->request(POST 'http://www.site.com/upload.php',
Content_Type => 'form-data',
Content => [
userfile => ["file.zip", "file.zip", "Content-Type" => "application/zip"],
],
);
print $res->as_string();
but the login part doesn't seem to work since I get a message that I am not logged in. |
|
#4
|
||||
|
||||
|
Mods, request move to perl forum
|
|
#5
|
|||
|
|||
|
Quote:
Sorry for posting in the wrong forum. Please a mod move this thread. i managed to login with this code: Code:
#!/usr/bin/perl
use strict;
use WWW::Mechanize;
use LWP::Debug qw(+);
my $url = "http://www.site.com/login.php";
my $username = "my_username";
my $password = "cmy_password";
my $mech = WWW::Mechanize->new();
$mech->get($url);
$mech->form_name('form1');
$mech->field(username => $username);
$mech->field(password => $password);
$mech->click();
Could someone give me some help for the upload script part? |
![]() |
| Viewing: Dev Shed Forums > Web Site Management > Scripts > Perl script : login + upload file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|