Over a million developers have joined DZone.

Simple FileFactory File Upload Tool

·

#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;

if ($#ARGV == -1)
{
        print "syntax: $0 \n";
        exit();
}

my $ua = LWP::UserAgent->new;
$ua->timeout(15);
$ua->requests_redirectable(['GET','POST']);
$ua->max_redirect(1);

my $response = $ua->get('http://www.filefactory.com/');
catch_unsuccess($response);
if ($response->content !~ /
/) { print STDERR "unable to initiate upload\n"; exit(1); } $response = $ua->post($1, ['redirect' => '1', 'file' => [$ARGV[0]]], 'content_type' => 'multipart/form-data'); catch_unsuccess($response); if ($response->content =~ //) { printf("upload successful!\n%s\n", $1); } sub catch_unsuccess { my ($response) = @_; if (!$response->is_success) { print STDERR $response->status_line . "\n"; exit(1); } }
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}