Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb Site ManagementScripts

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 3rd, 2007, 11:23 AM
axelfc axelfc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 47 axelfc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 43 m 5 sec
Reputation Power: 4
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">&nbsp;</p>
  <p align="center">
  <input type="file" name="userfile"/>
  </p>    
  <p align="center">
  <input name="submit" type="submit"  value="upload"/>
  </p>
</form>   

Reply With Quote
  #2  
Old July 3rd, 2007, 11:35 AM
Axweildr's Avatar
Axweildr Axweildr is offline
CPAN medic ...
Dev Shed God 13th Plane (11000 - 11499 posts)
 
Join Date: Mar 2003
Location: Location: Location:
Posts: 11,401 Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)  Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 2 Days 2 h 24 m 22 sec
Reputation Power: 2784
Send a message via Google Talk to Axweildr
Orkut
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 ...

Reply With Quote
  #3  
Old July 3rd, 2007, 11:41 AM
axelfc axelfc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 47 axelfc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 43 m 5 sec
Reputation Power: 4
Quote:
Originally Posted by Axweildr
Why not use php instead of perl? There's many examples in both Perl and PHP, what have you tried searching for ...?


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.

Reply With Quote
  #4  
Old July 3rd, 2007, 12:12 PM
Axweildr's Avatar
Axweildr Axweildr is offline
CPAN medic ...
Dev Shed God 13th Plane (11000 - 11499 posts)
 
Join Date: Mar 2003
Location: Location: Location:
Posts: 11,401 Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)Axweildr User rank is General 27th Grade (Above 100000 Reputation Level)  Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1Folding Points: 124792 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 2 Days 2 h 24 m 22 sec
Reputation Power: 2784
Send a message via Google Talk to Axweildr
Orkut
Mods, request move to perl forum

Reply With Quote
  #5  
Old July 3rd, 2007, 01:20 PM
axelfc axelfc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 47 axelfc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 43 m 5 sec
Reputation Power: 4
Quote:
Originally Posted by Axweildr
Mods, request move to perl forum


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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb Site ManagementScripts > Perl script : login + upload file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT