I want to get the file from one host to another host. We can get the file using the NET::FTP module. In that module we can use the get
method to get the file. But I want the file contents instead of the file. I know that using the read
method we can read the file contents. But how do I call the read
function and how do I get the file contents?
views:
128answers:
2File::Remote uses rcp/scp, muruga's question talks about FTP.
daxim
2010-05-13 07:39:05
+2
A:
From the Net::FTP
documentation:
get ( REMOTE_FILE [, LOCAL_FILE [, WHERE]] )
Get REMOTE_FILE from the server and store locally. LOCAL_FILE may be a filename or a filehandle.
So just store the file directly into a variable attached to a filehandle.
use Net::FTP ();
my $ftp = Net::FTP->new('ftp.kde.org', Debug => 0)
or die "Cannot connect to some.host.name: $@";
$ftp->login('anonymous', '-anonymous@')
or die 'Cannot login ', $ftp->message;
$ftp->cwd('/pub/kde')
or die 'Cannot change working directory ', $ftp->message;
my ($remote_file_content, $remote_file_handle);
open($remote_file_handle, '>', \$remote_file_content);
$ftp->get('README', $remote_file_handle)
or die "get failed ", $ftp->message;
$ftp->quit;
print $remote_file_content;
daxim
2010-05-13 07:49:54