NAME
Net::FTP::Common - Perl extension for simplifying common usages of Net::FTP.
SYNOPSIS
use Net::FTP::Common;
%net_ftp_config = ( Debug => 1, Timeout => 120 );
%common_cfg =
(
User => 'username', # overwrite anonymous user default
Pass => 'password', # overwrite list@rebol.com pass default
Dir => 'pub', # overwrite slash default
Type => 'A' # overwrite I (binary) default
);
$ez = Net::FTP::Common->new(\%net_ftp_config, \%common_cfg);
$host = 'ftp.rebol.com';
# Get a listing of a remote directory:
@listing = $ez->dir($host);
# Make a directory on the remote machine
$ez->mkdir($host, Dir => '/pub/newdir/1/2/3', Recurse => 1);
# Get a file from the remote machine
$ez->get($host, File => 'codex.txt', LocalFile => '/tmp/crypto.txt');
# Send a file to the remote machine
$ez->send($host, File => 'codex.txt');
# test for a file's existence on the remote machine (using =~)
@file = $ez->grep($host, File => '[A-M]*[.]txt');
# a synonym for grep is glob (no difference, just another name)
@file = $ez->glob($host, File => 'n.*-file.t?t');
# test for a file on the remote machine (using eq)
$ez->check($host, File => 'needed-file.txt');
# note this is no more than you manually calling:
# (scalar grep { $_ = 'needed-file.txt' } $ez->dir($host)) > 0;
# or manually calling
# (scalar $ez->grep($host, File => 'needed-file.txt')) > 0
# can we login to the machine?
$ez->login($host) || die "cant login: $@";
DESCRIPTION
This module is intended to make the common uses of Net::FTP a one-line affair. Also, it made the development of Net::FTP::Shell straightfoward.
Note well: though Net::FTP works in the stateful way that the FTP protocol does, Net::FTP::Common works in a stateless "one-hit" fashion. That is, for each separate call to the API, a connection is established, the particular Net::FTP::Common functionality is performed and the connection is dropped. The disadvantage of this approach is the (usually irrelevant and insignificant) over head of connection and disconnection. The advantage is that there is much less chance of incurring failure due to timeout.
TRAPS FOR THE UNWARY
-
@file = $ez->grep($host, File => '[A-M]*[.]txt');
is correct
@file = $ez->grep($host, '[A-M]*[.]txt');
looks correct but is not because you did not name the argument as you are supposed to.
In the current dain-bramaged interface, you can catch the bozak when you accidentally forget to specify the $host argument to Net::FTP::Common's API functions.
Since no one seems to be using this, I may in fact rework the API to allow the host to be a default instead of requiring it's specification.
EXPORT
None by default.
AUTHOR
T. M. Brannon <tbone@cpan.org>
SEE ALSO
REBOL (www.rebol.com) is a language which supports 1-line internet processing for the schemes of mailto:, http:, daytime:, and ftp:.
A Perl implementation of REBOL is in the works at www.metaperl.com.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 295:
'=item' outside of any '=over'
- Around line 316:
You forgot a '=back' before '=head2'