PUTting using FTP

Eric Lease Morgan (eric_morgan@ncsu.edu)
Mon, 02 Jun 1997 10:00:28 -0400


How do I PUT files using the FTP functions of the LWP library?

Using the LWP library, I would like to PUT a file on a remote machine
via FTP. The script below correctly creates a file on the remote
machine, but the file is 0 bytes long. I believe the syntax I am using
to PUT the file is incomplete:

#!/usr/local/bin/perl

# include the necessary libraries
use LWP::UserAgent;
use HTTP::Request;

# define the URL of the file to put ($u)
$u = "ftp://username:password\@site.org/test.txt";

# create the user agent ($a)
$a = new LWP::UserAgent;

# create the requeset ($r)
# does the following command need to know the local file name?
$r = new HTTP::Request 'PUT', "$u";

# PUT it and save the output ($o)
$o = $a->request($r);

# print the output
print $o->content;

# quit gracefully
exit;


In short, what is the complete syntax to copy a local file to a remote
machine with FTP using the LWP library?

-- 
Eric Lease Morgan
NCSU Libraries
http://www.lib.ncsu.edu/staff/morgan/