The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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
     );


  $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');

  # Send a file to the remote machine
  $ez->send($host, File => 'codex.txt');

  # test for a file's existence on the remote machine (slash defaultusing eq)
  $ez->grep($host, File => 'needed-file.txt');

  # 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)) > 0


  # test for a file on the remote machine (using =~)
  $ez->glob($host, File => 'n.*-file.t?t');
  # note this is no more than you manually calling:
  # (scalar grep { $_ =~ 'n.*-file.t?t' } $ez->dir($host)) > 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.

EXPORT

None by default.

AUTHOR

T. M. Brannon <tbone@cpan.org>

SEE ALSO

REBOL (www.metaperl.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.