#!/usr/bin/perl -w #local-variable cperl-mode =head1 NAME Slashtmp utility - upload files to slashtmp from the command line. =head1 SYNOPSIS Run this from the command line, specifying the options you care about. ./slashtmp some-file # Upload some-file to slashtmp with default settings ./slashtmp -a some-file # Upload some file, user must authenticate to download ./slashtmp -desc "this is a description" some-file # etc... =cut use Term::ReadKey; use WWW::Mechanize; use MIME::Base64; use Getopt::Long; use constant USAGE => < Description of options: --auth, -a : User must authenticate to download this file (default: false) --desc, -d : Provide a description. Must quote if more than one word, of course. Default: blank --pass, -p : Provide a decription password. Default: blank Everything but the filename is optional. DONE my ($auth, $desc, $pass) = ( 0, '', '' ); GetOptions( "auth" => \$auth, "desc:s" => \$desc, "pass:s" => \$pass ); my $fname = shift @ARGV; die USAGE unless defined $fname and -e $fname and -r $fname; # grab username and password print "username: "; my $username = ReadLine( 0 ); print "password: "; ReadMode( 'noecho' ); my $password = ReadLine( 0 ); ReadMode( 'normal' ); chomp $username; chomp $password; # everything seems good, let's upload. my $mech = new WWW::Mechanize; $mech->agent_alias( 'Windows IE 6' ); $mech->credentials( $username, $password ); my @args = ( Authentication => "Basic " . MIME::Base64::encode( $username . ":" . $password ) ); $mech->get( 'https://www.slashtmp.iu.edu', @args ); $mech->submit_form( form_name => 'f1', fields => { UFILE => $fname, DESCRIPTION => $desc, PASSWORD => $pass, authdown => ($auth) ? 1 : undef }, ); if( $mech->success ) { # grab the download link my $prefix = "https://www.slashtmp.iu.edu/public/download.php"; $mech->content =~ m||; print "\nUploaded to\n\t$prefix$1\n"; } else { print "\nThere was an error...\n"; }