Re: Put with libwww
Marc Langheinrich (marclang@cs.washington.edu)
Tue, 16 Mar 1999 21:00:55 +0900
On Tue, Mar 16, 1999 at 11:13:49AM +0100, Christophe Chevalier wrote:
> I seek to write a file on a site ftp with the method PUT. It seems that
> the library "libwww" is the solution, but I did not find any example.
>
> Do you have any example to propose to me ?
$filename = $ARGV[0] || die <<USAGE;
Usage: $0 <filename>
File will be uploaded to the ACME Test Server under the
foo/bar/baz directory
USAGE
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->env_proxy; # initialize from environment variables
my $serverURI = 'http://bogus.acme.org/foo/bar/baz';
my $req = HTTP::Request->new(PUT => "$serverURI/$filename");
$req->authorization_basic('my_user_name', 'my_password');
$req->content_type('text/html');
print "Opening $filename...\n";
open (FILE, $filename) or die "Could not open $filename: $!";
my $content = join ('', <FILE>);
print "Read ". length($content) . " bytes from disk.\n";
$req->content($content);
print "Saving at $serverURI/$filename...\n";
print $ua->request($req)->as_string;
--
Marc Langheinrich
marclang@cs.washington.edu