Net::FTP::Common

Simplify common usages of Net::FTP
Download

Net::FTP::Common Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Terrence Brannon
  • Publisher web site:
  • http://search.cpan.org/~tbone/

Net::FTP::Common Tags


Net::FTP::Common Description

Simplify common usages of Net::FTP Net::FTP::Common is a Perl module intended to make the common uses of Net::FTP a one-line, no-argument affair. In other words, you have 100% programming with Net::FTP. With Net::FTP::Common you will have 95% configuration and 5% programming.The way that it makes it a one-line affair is that the common pre-phase of login, cd, file type (binary/ascii) is handled for you. The way that it makes usage a no-argument affair is by pulling things from the hash that configured it at construction time. Should arguments be supplied to any API function, then these changes are applied to the hash of the object's state and used by any future-called API function which might need them.Usage of this module is intended to be straightforward and stereotyped. The general steps to be used are: * use Net::FTP::Common * Define FTP configuration information This can be inlined within the script but oftentimes this will be stored in a module for usage in many other scripts. * Use a Net::FTP::Common API function Note well that you NEVER have to login first. All API functions automatically log you in and change to the configured or specified directory. However, sometimes it is useful to see if you can actually login before attempting to do something else on an FTP site. This is the only time you will need the login() API method.SYNOPSIS our %netftp_cfg = (Debug => 1, Timeout => 120); our %common_cfg = ( # # The first 2 options, if not present, # lead to relying on .netrc for login # User => 'anonymous', Pass => 'tbone@cpan.org', # # Other options # LocalFile => 'delete.zip' # setup something for $ez->get Host => 'ftp.fcc.gov', # overwrite ftp.microsoft.com default LocalDir => '/tmp', RemoteDir => '/', # automatic CD on remote machine to RemoteDir Type => 'A' # overwrite I (binary) TYPE default ); # NOTE WELL!!! one constructor arg is passed by reference, the # other by value. This is inconsistent, but still it is A Good Thing. # Believe me! I thought about this. And I have a good reason for it: # This is to allow the least modification of legacy Net::FTP source code. $ez = Net::FTP::Common->new(\%common_cfg, %netftp_config); # can we login to the machine? # Note: it is NEVER necessary to first login before calling # Net::FTP::Common API functions. # This function is just for checking to see if a machine is up. # It is published as part of the API because I have found it # useful when writing FTP scripts which scan for the # first available FTP site to use for upload. The exact # call-and-return semantics for this function are described # and justified below. $ez->login or die "cant login: $@"; # Get a listing of a remote directory @listing = $ez->ls; # Let's list a different directory, over-riding and changing the # default directory @listing = $ez->ls(RemoteDir => '/pub/rfcs'); # Let's list the default dir on several hosts @host_listings = map { $ez->ls(Host => $_) } @host_list # Let's get the listings of several directories @dir_listings = map { $ez->ls(RemoteDir => $_) } @dir_list; # Let's get a detailed directory listing... (thanks Kevin!) %listing = $ez->dir; # Note this is a hash, not an array return value. ### representative output 'test' => { 'owner' => 'root', 'month' => 'Jan', 'linkTarget' => undef, 'inode' => '1', 'size' => '6', 'group' => 'root', 'yearOrTime' => '1999', 'day' => '27', 'perm' => '-rw-r--r--' }, 'ranc' => { 'owner' => 'root', 'month' => 'Oct', 'linkTarget' => undef, 'inode' => '2', 'size' => '4096', 'group' => 'root', 'yearOrTime' => '00:42', 'day' => '31', 'perm' => 'drwxr-xr-x' } # Get a file from the remote machine $ez->get(RemoteFile => 'codex.txt', LocalFile => '/tmp/crypto.txt'); # Get a file from the remote machine, specifying dir: $ez->get(RemoteFile => 'codex.txt', LocalDir => '/tmp'); # NOTE WELL: because the prior call set LocalFile, it is still a # part of the object store. In other words this example will try # to store the downloaded file in /tmp/tmp/crypto.txt. # Better to say: $ez->get(RemoteFile => 'codex.txt', LocalDir => '/tmp', LocalFile => ''); # Send a file to the remote machine (*dont* use put!) $ez->send(RemoteFile => 'codex.txt'); # test for a file's existence on the remote machine (using =~) @file = $ez->grep(Grep => qr/*txt/); # test for a file on the remote machine (using eq) $ez->exists(RemoteFile => 'needed-file.txt'); # note this is no more than you manually calling: # (scalar grep { $_ eq 'needed-file.txt' } $ez->ls) > 0; # Let's get all output written to STDERR to goto a logfile my $ez = Net::FTP::Common->new( { G, STDERR => $logfile }, %netftp_cfg); Requirements: · Perl


Net::FTP::Common Related Software