home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / Perl / Perl_Libs / site_perl / Net / FTP.pm < prev    next >
Encoding:
Perl POD Document  |  1997-12-11  |  31.3 KB  |  1,385 lines

  1. # Net::FTP.pm
  2. #
  3. # Copyright (c) 1995 Graham Barr <gbarr@pobox.com>. All rights reserved.
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the same terms as Perl itself.
  6. #
  7. # Documentation (at end) improved 1996 by Nathan Torkington <gnat@frii.com>.
  8.  
  9. package Net::FTP;
  10.  
  11. require 5.001;
  12.  
  13. use strict;
  14. use vars qw(@ISA $VERSION);
  15. use Carp;
  16.  
  17. use Socket 1.3;
  18. use IO::Socket;
  19. use Time::Local;
  20. use Net::Cmd;
  21. use Net::Config;
  22. # use AutoLoader qw(AUTOLOAD);
  23.  
  24. $VERSION = "2.32"; # $Id: //depot/libnet/Net/FTP.pm#17$
  25. @ISA     = qw(Exporter Net::Cmd IO::Socket::INET);
  26.  
  27. # Someday I will "use constant", when I am not bothered to much about
  28. # compatability with older releases of perl
  29.  
  30. use vars qw($TELNET_IAC $TELNET_IP $TELNET_DM);
  31. ($TELNET_IAC,$TELNET_IP,$TELNET_DM) = (255,244,242);
  32.  
  33. # Name is too long for AutoLoad, it clashes with pasv_xfer
  34. sub pasv_xfer_unique {
  35.     my($sftp,$sfile,$dftp,$dfile) = @_;
  36.     $sftp->pasv_xfer($sfile,$dftp,$dfile,1);
  37. }
  38.  
  39. 1;
  40. # Having problems with AutoLoader
  41. #__END__
  42.  
  43. sub new
  44. {
  45.  my $pkg  = shift;
  46.  my $peer = shift;
  47.  my %arg  = @_; 
  48.  
  49.  my $host = $peer;
  50.  my $fire = undef;
  51.  
  52.  # Should I use Net::Ping here ?? --GMB
  53.  if(exists($arg{Firewall}) || !defined(inet_aton($peer)))
  54.   {
  55.    $fire = $arg{Firewall}
  56.     || $ENV{FTP_FIREWALL}
  57.     || $NetConfig{ftp_firewall}
  58.     || undef;
  59.  
  60.    if(defined $fire)
  61.     {
  62.      $peer = $fire;
  63.      delete $arg{Port};
  64.     }
  65.   }
  66.  
  67.  my $ftp = $pkg->SUPER::new(PeerAddr => $peer, 
  68.                 PeerPort => $arg{Port} || 'ftp(21)',
  69.                 Proto    => 'tcp',
  70.                 Timeout  => defined $arg{Timeout}
  71.                         ? $arg{Timeout}
  72.                         : 120
  73.                ) or return undef;
  74.  
  75.  ${*$ftp}{'net_ftp_host'}     = $host;        # Remote hostname
  76.  ${*$ftp}{'net_ftp_type'}     = 'A';        # ASCII/binary/etc mode
  77.  
  78.  ${*$ftp}{'net_ftp_firewall'} = $fire
  79.     if(defined $fire);
  80.  
  81.  ${*$ftp}{'net_ftp_passive'} = int
  82.     exists $arg{Passive}
  83.         ? $arg{Passive}
  84.         : exists $ENV{FTP_PASSIVE}
  85.         ? $ENV{FTP_PASSIVE}
  86.         : defined $fire
  87.             ? $NetConfig{ftp_ext_passive}
  88.             : $NetConfig{ftp_int_passive};    # Whew! :-)
  89.  
  90.  $ftp->autoflush(1);
  91.  
  92.  $ftp->debug(exists $arg{Debug} ? $arg{Debug} : undef);
  93.  
  94.  unless ($ftp->response() == CMD_OK)
  95.   {
  96.    $ftp->close();
  97.    $@ = $ftp->message;
  98.    undef $ftp;
  99.   }
  100.  
  101.  $ftp;
  102. }
  103.  
  104. ##
  105. ## User interface methods
  106. ##
  107.  
  108. sub quit
  109. {
  110.  my $ftp = shift;
  111.  
  112.  $ftp->_QUIT;
  113.  $ftp->close;
  114. }
  115.  
  116. sub DESTROY
  117. {
  118.  my $ftp = shift;
  119.  defined(fileno($ftp)) && $ftp->quit
  120. }
  121.  
  122. sub ascii  { shift->type('A',@_); }
  123. sub binary { shift->type('I',@_); }
  124.  
  125. sub ebcdic
  126. {
  127.  carp "TYPE E is unsupported, shall default to I";
  128.  shift->type('E',@_);
  129. }
  130.  
  131. sub byte
  132. {
  133.  carp "TYPE L is unsupported, shall default to I";
  134.  shift->type('L',@_);
  135. }
  136.  
  137. # Allow the user to send a command directly, BE CAREFUL !!
  138.  
  139. sub quot
  140.  my $ftp = shift;
  141.  my $cmd = shift;
  142.  
  143.  $ftp->command( uc $cmd, @_);
  144.  $ftp->response();
  145. }
  146.  
  147. sub mdtm
  148. {
  149.  my $ftp  = shift;
  150.  my $file = shift;
  151.  
  152.  $ftp->_MDTM($file) && $ftp->message =~ /(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/
  153.     ? timegm($6,$5,$4,$3,$2-1,$1 - 1900)
  154.     : undef;
  155. }
  156.  
  157. sub size
  158. {
  159.  my $ftp  = shift;
  160.  my $file = shift;
  161.  
  162.  $ftp->_SIZE($file)
  163.     ? ($ftp->message =~ /(\d+)/)[0]
  164.     : undef;
  165. }
  166.  
  167. sub login
  168. {
  169.  my($ftp,$user,$pass,$acct) = @_;
  170.  my($ok,$ruser);
  171.  
  172.  unless (defined $user)
  173.   {
  174.    require Net::Netrc;
  175.  
  176.    my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'});
  177.  
  178.    ($user,$pass,$acct) = $rc->lpa()
  179.     if ($rc);
  180.   }
  181.  
  182.  $user ||= "anonymous";
  183.  $ruser = $user;
  184.  
  185.  if(defined ${*$ftp}{'net_ftp_firewall'})
  186.   {
  187.    $user .= "@" . ${*$ftp}{'net_ftp_host'};
  188.   }
  189.  
  190.  $ok = $ftp->_USER($user);
  191.  
  192.  # Some dumb firewalls don't prefix the connection messages
  193.  $ok = $ftp->response()
  194.     if($ok == CMD_OK && $ftp->code == 220 && $user =~ /\@/);
  195.  
  196.  if ($ok == CMD_MORE)
  197.   {
  198.    unless(defined $pass)
  199.     {
  200.      require Net::Netrc;
  201.  
  202.      my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'}, $ruser);
  203.  
  204.      ($ruser,$pass,$acct) = $rc->lpa()
  205.     if ($rc);
  206.  
  207.      $pass = eval { "-" . (getpwuid($>))[0] . "@" }
  208.         if (!defined $pass && (!defined($ruser) || $ruser =~ /^anonymous/o));
  209.     }
  210.  
  211.    $ok = $ftp->_PASS($pass || "");
  212.   }
  213.  
  214.  $ok = $ftp->_ACCT($acct || "")
  215.     if ($ok == CMD_MORE);
  216.  
  217.  $ftp->authorize()
  218.     if($ok == CMD_OK && defined ${*$ftp}{'net_ftp_firewall'});
  219.  
  220.  $ok == CMD_OK;
  221. }
  222.  
  223. sub account
  224. {
  225.  @_ == 2 or croak 'usage: $ftp->account( ACCT )';
  226.  my $ftp = shift;
  227.  my $acct = shift;
  228.  $ftp->_ACCT($acct) == CMD_OK;
  229. }
  230.  
  231. sub authorize
  232. {
  233.  @_ >= 1 || @_ <= 3 or croak 'usage: $ftp->authorize( [AUTH [, RESP]])';
  234.  
  235.  my($ftp,$auth,$resp) = @_;
  236.  
  237.  unless(defined $resp)
  238.   {
  239.    require Net::Netrc;
  240.  
  241.    $auth ||= eval { (getpwuid($>))[0] };
  242.  
  243.    my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'}, $auth)
  244.         || Net::Netrc->lookup(${*$ftp}{'net_ftp_firewall'});
  245.  
  246.    ($auth,$resp) = $rc->lpa()
  247.      if($rc);
  248.   }
  249.  
  250.  my $ok = $ftp->_AUTH($auth || "");
  251.  
  252.  $ok = $ftp->_RESP($resp || "")
  253.     if ($ok == CMD_MORE);
  254.  
  255.  $ok == CMD_OK;
  256. }
  257.  
  258. sub rename
  259. {
  260.  @_ == 3 or croak 'usage: $ftp->rename(FROM, TO)';
  261.  
  262.  my($ftp,$from,$to) = @_;
  263.  
  264.  $ftp->_RNFR($from)
  265.     && $ftp->_RNTO($to);
  266. }
  267.  
  268. sub type
  269. {
  270.  my $ftp = shift;
  271.  my $type = shift;
  272.  my $oldval = ${*$ftp}{'net_ftp_type'};
  273.  
  274.  return $oldval
  275.     unless (defined $type);
  276.  
  277.  return undef
  278.     unless ($ftp->_TYPE($type,@_));
  279.  
  280.  ${*$ftp}{'net_ftp_type'} = join(" ",$type,@_);
  281.  
  282.  $oldval;
  283. }
  284.  
  285. sub abort
  286. {
  287.  my $ftp = shift;
  288.  
  289.  send($ftp,pack("CC",$TELNET_IAC,$TELNET_IP),0);
  290.  send($ftp,pack("CC", $TELNET_IAC, $TELNET_DM),MSG_OOB);
  291.  
  292.  $ftp->command("ABOR");
  293.  
  294. # defined ${*$ftp}{'net_ftp_dataconn'}
  295. #    ? ${*$ftp}{'net_ftp_dataconn'}->close()
  296. #    : $ftp->response();
  297.  
  298.  ${*$ftp}{'net_ftp_dataconn'}->close()
  299.     if defined ${*$ftp}{'net_ftp_dataconn'};
  300.  
  301.  $ftp->response();
  302. #    if $ftp->status == CMD_REJECT;
  303.  
  304.  $ftp->status == CMD_OK;
  305. }
  306.  
  307. sub get
  308. {
  309.  my($ftp,$remote,$local,$where) = @_;
  310.  
  311.  my($loc,$len,$buf,$resp,$localfd,$data);
  312.  local *FD;
  313.  
  314.  $localfd = ref($local) ? fileno($local)
  315.             : undef;
  316.  
  317.  ($local = $remote) =~ s#^.*/##
  318.     unless(defined $local);
  319.  
  320.  ${*$ftp}{'net_ftp_rest'} = $where
  321.     if ($where);
  322.  
  323.  delete ${*$ftp}{'net_ftp_port'};
  324.  delete ${*$ftp}{'net_ftp_pasv'};
  325.  
  326.  $data = $ftp->retr($remote) or
  327.     return undef;
  328.  
  329.  if(defined $localfd)
  330.   {
  331.    $loc = $local;
  332.   }
  333.  else
  334.   {
  335.    $loc = \*FD;
  336.  
  337.    unless(($where) ? open($loc,">>$local") : open($loc,">$local"))
  338.     {
  339.      carp "Cannot open Local file $local: $!\n";
  340.      $data->abort;
  341.      return undef;
  342.     }
  343.   }
  344.  
  345.  if($ftp->type eq 'I' && !binmode($loc))
  346.   {
  347.    carp "Cannot binmode Local file $local: $!\n";
  348.    $data->abort;
  349.    return undef;
  350.   }
  351.  
  352.  $buf = '';
  353.  
  354.  do
  355.   {
  356.    $len = $data->read($buf,1024);
  357.   }
  358.  while($len > 0 && syswrite($loc,$buf,$len) == $len);
  359.  
  360.  close($loc)
  361.     unless defined $localfd;
  362.  
  363.  $data->close(); # implied $ftp->response
  364.  
  365.  return $local;
  366. }
  367.  
  368. sub cwd
  369. {
  370.  @_ == 2 || @_ == 3 or croak 'usage: $ftp->cwd( [ DIR ] )';
  371.  
  372.  my($ftp,$dir) = @_;
  373.  
  374.  $dir ||= "/";
  375.  
  376.  $dir eq ".."
  377.     ? $ftp->_CDUP()
  378.     : $ftp->_CWD($dir);
  379. }
  380.  
  381. sub cdup
  382. {
  383.  @_ == 1 or croak 'usage: $ftp->cdup()';
  384.  $_[0]->_CDUP;
  385. }
  386.  
  387. sub pwd
  388. {
  389.  @_ == 1 || croak 'usage: $ftp->pwd()';
  390.  my $ftp = shift;
  391.  
  392.  $ftp->_PWD();
  393.  $ftp->_extract_path;
  394. }
  395.  
  396. sub rmdir
  397. {
  398.  @_ == 2 || croak 'usage: $ftp->rmdir( DIR )';
  399.  
  400.  $_[0]->_RMD($_[1]);
  401. }
  402.  
  403. sub mkdir
  404. {
  405.  @_ == 2 || @_ == 3 or croak 'usage: $ftp->mkdir( DIR [, RECURSE ] )';
  406.  
  407.  my($ftp,$dir,$recurse) = @_;
  408.  
  409.  $ftp->_MKD($dir) || $recurse or
  410.     return undef;
  411.  
  412.  my $path = $dir;
  413.  
  414.  unless($ftp->ok)
  415.   {
  416.    my @path = split(m#(?=/+)#, $dir);
  417.  
  418.    $path = "";
  419.  
  420.    while(@path)
  421.     {
  422.      $path .= shift @path;
  423.  
  424.      $ftp->_MKD($path);
  425.      $path = $ftp->_extract_path($path);
  426.  
  427.      # 521 means directory already exists
  428.      last
  429.         unless $ftp->ok || $ftp->code == 521 || $ftp->code == 550;
  430.     }
  431.   }
  432.  
  433.  $ftp->_extract_path($path);
  434. }
  435.  
  436. sub delete
  437. {
  438.  @_ == 2 || croak 'usage: $ftp->delete( FILENAME )';
  439.  
  440.  $_[0]->_DELE($_[1]);
  441. }
  442.  
  443. sub put        { shift->_store_cmd("stor",@_) }
  444. sub put_unique { shift->_store_cmd("stou",@_) }
  445. sub append     { shift->_store_cmd("appe",@_) }
  446.  
  447. sub nlst { shift->_data_cmd("NLST",@_) }
  448. sub list { shift->_data_cmd("LIST",@_) }
  449. sub retr { shift->_data_cmd("RETR",@_) }
  450. sub stor { shift->_data_cmd("STOR",@_) }
  451. sub stou { shift->_data_cmd("STOU",@_) }
  452. sub appe { shift->_data_cmd("APPE",@_) }
  453.  
  454. sub _store_cmd 
  455. {
  456.  my($ftp,$cmd,$local,$remote) = @_;
  457.  my($loc,$sock,$len,$buf,$localfd);
  458.  local *FD;
  459.  
  460.  $localfd = ref($local) ? fileno($local)
  461.             : undef;
  462.  
  463.  unless(defined $remote)
  464.   {
  465.    croak 'Must specify remote filename with stream input'
  466.     if defined $localfd;
  467.  
  468.    ($remote = $local) =~ s%.*/%%;
  469.   }
  470.  
  471.  if(defined $localfd)
  472.   {
  473.    $loc = $local;
  474.   }
  475.  else
  476.   {
  477.    $loc = \*FD;
  478.  
  479.    unless(open($loc,"<$local"))
  480.     {
  481.      carp "Cannot open Local file $local: $!\n";
  482.      return undef;
  483.     }
  484.   }
  485.  
  486.  if($ftp->type eq 'I' && !binmode($loc))
  487.   {
  488.    carp "Cannot binmode Local file $local: $!\n";
  489.    return undef;
  490.   }
  491.  
  492.  delete ${*$ftp}{'net_ftp_port'};
  493.  delete ${*$ftp}{'net_ftp_pasv'};
  494.  
  495.  $sock = $ftp->_data_cmd($cmd, $remote) or 
  496.     return undef;
  497.  
  498.  while(1)
  499.   {
  500.    last unless $len = sysread($loc,$buf="",1024);
  501.  
  502.    unless($sock->write($buf,$len) == $len)
  503.     {
  504.      $sock->abort;
  505.      close($loc)
  506.     unless defined $localfd;
  507.      return undef;
  508.     }
  509.   }
  510.  
  511.  $sock->close();
  512.  
  513.  close($loc)
  514.     unless defined $localfd;
  515.  
  516.  ($remote) = $ftp->message =~ /unique file name:\s*(\S*)\s*\)/
  517.     if ('STOU' eq uc $cmd);
  518.  
  519.  return $remote;
  520. }
  521.  
  522. sub port
  523. {
  524.  @_ == 1 || @_ == 2 or croak 'usage: $ftp->port([PORT])';
  525.  
  526.  my($ftp,$port) = @_;
  527.  my $ok;
  528.  
  529.  delete ${*$ftp}{'net_ftp_intern_port'};
  530.  
  531.  unless(defined $port)
  532.   {
  533.    # create a Listen socket at same address as the command socket
  534.  
  535.    ${*$ftp}{'net_ftp_listen'} ||= IO::Socket::INET->new(Listen    => 5,
  536.                                         Proto     => 'tcp',
  537.                                         LocalAddr => $ftp->sockhost, 
  538.                                        );
  539.   
  540.    my $listen = ${*$ftp}{'net_ftp_listen'};
  541.  
  542.    my($myport, @myaddr) = ($listen->sockport, split(/\./,$listen->sockhost));
  543.  
  544.    $port = join(',', @myaddr, $myport >> 8, $myport & 0xff);
  545.  
  546.    ${*$ftp}{'net_ftp_intern_port'} = 1;
  547.   }
  548.  
  549.  $ok = $ftp->_PORT($port);
  550.  
  551.  ${*$ftp}{'net_ftp_port'} = $port;
  552.  
  553.  $ok;
  554. }
  555.  
  556. sub ls  { shift->_list_cmd("NLST",@_); }
  557. sub dir { shift->_list_cmd("LIST",@_); }
  558.  
  559. sub pasv
  560. {
  561.  @_ == 1 or croak 'usage: $ftp->pasv()';
  562.  
  563.  my $ftp = shift;
  564.  
  565.  delete ${*$ftp}{'net_ftp_intern_port'};
  566.  
  567.  $ftp->_PASV && $ftp->message =~ /(\d+(,\d+)+)/
  568.     ? ${*$ftp}{'net_ftp_pasv'} = $1
  569.     : undef;    
  570. }
  571.  
  572. sub unique_name
  573. {
  574.  my $ftp = shift;
  575.  ${*$ftp}{'net_ftp_unique'} || undef;
  576. }
  577.  
  578. sub supported {
  579.     @_ == 2 or croak 'usage: $ftp->supported( CMD )';
  580.     my $ftp = shift;
  581.     my $cmd = uc shift;
  582.     my $hash = ${*$ftp}{'net_ftp_supported'} ||= {};
  583.  
  584.     return $hash->{$cmd}
  585.         if exists $hash->{$cmd};
  586.  
  587.     my $ok = $ftp->_HELP($cmd) &&
  588.         $ftp->message !~ /unimplemented/i;
  589.  
  590.     $hash->{$cmd} = $ok;
  591. }
  592.  
  593. ##
  594. ## Depreciated methods
  595. ##
  596.  
  597. sub lsl
  598. {
  599.  carp "Use of Net::FTP::lsl depreciated, use 'dir'"
  600.     if $^W;
  601.  goto &dir;
  602. }
  603.  
  604. sub authorise
  605. {
  606.  carp "Use of Net::FTP::authorise depreciated, use 'authorize'"
  607.     if $^W;
  608.  goto &authorize;
  609. }
  610.  
  611.  
  612. ##
  613. ## Private methods
  614. ##
  615.  
  616. sub _extract_path
  617. {
  618.  my($ftp, $path) = @_;
  619.  
  620.  # This tries to work both with and without the quote doubling
  621.  # convention (RFC 959 requires it, but the first 3 servers I checked
  622.  # didn't implement it).  It will fail on a server which uses a quote in
  623.  # the message which isn't a part of or surrounding the path.
  624.  $ftp->ok &&
  625.     $ftp->message =~ /(?:^|\s)\"(.*)\"(?:$|\s)/ &&
  626.     ($path = $1) =~ s/\"\"/\"/g;
  627.  
  628.  $path;
  629. }
  630.  
  631. ##
  632. ## Communication methods
  633. ##
  634.  
  635. sub _dataconn
  636. {
  637.  my $ftp = shift;
  638.  my $data = undef;
  639.  my $pkg = "Net::FTP::" . $ftp->type;
  640.  
  641.  eval "require " . $pkg;
  642.  
  643.  $pkg =~ s/ /_/g;
  644.  
  645.  delete ${*$ftp}{'net_ftp_dataconn'};
  646.  
  647.  if(defined ${*$ftp}{'net_ftp_pasv'})
  648.   {
  649.    my @port = split(/,/,${*$ftp}{'net_ftp_pasv'});
  650.  
  651.    $data = $pkg->new(PeerAddr => join(".",@port[0..3]),
  652.                      PeerPort => $port[4] * 256 + $port[5],
  653.                      Proto    => 'tcp'
  654.                     );
  655.   }
  656.  elsif(defined ${*$ftp}{'net_ftp_listen'})
  657.   {
  658.    $data = ${*$ftp}{'net_ftp_listen'}->accept($pkg);
  659.    close(delete ${*$ftp}{'net_ftp_listen'});
  660.   }
  661.  
  662.  if($data)
  663.   {
  664.    ${*$data} = "";
  665.    $data->timeout($ftp->timeout);
  666.    ${*$ftp}{'net_ftp_dataconn'} = $data;
  667.    ${*$data}{'net_ftp_cmd'} = $ftp;
  668.   }
  669.  
  670.  $data;
  671. }
  672.  
  673. sub _list_cmd
  674. {
  675.  my $ftp = shift;
  676.  my $cmd = uc shift;
  677.  
  678.  delete ${*$ftp}{'net_ftp_port'};
  679.  delete ${*$ftp}{'net_ftp_pasv'};
  680.  
  681.  my $data = $ftp->_data_cmd($cmd,@_);
  682.  
  683.  return undef
  684.     unless(defined $data);
  685.  
  686.  require Net::FTP::A;
  687.  bless $data, "Net::FTP::A"; # Force ASCII mode
  688.  
  689.  my $databuf = '';
  690.  my $buf = '';
  691.  
  692.  while($data->read($databuf,1024))
  693.   {
  694.    $buf .= $databuf;
  695.   }
  696.  
  697.  my $list = [ split(/\n/,$buf) ];
  698.  
  699.  $data->close();
  700.  
  701.  wantarray ? @{$list}
  702.            : $list;
  703. }
  704.  
  705. sub _data_cmd
  706. {
  707.  my $ftp = shift;
  708.  my $cmd = uc shift;
  709.  my $ok = 1;
  710.  my $where = delete ${*$ftp}{'net_ftp_rest'} || 0;
  711.  
  712.  if(${*$ftp}{'net_ftp_passive'} &&
  713.      !defined ${*$ftp}{'net_ftp_pasv'} &&
  714.      !defined ${*$ftp}{'net_ftp_port'})
  715.   {
  716.    my $data = undef;
  717.  
  718.    $ok = defined $ftp->pasv;
  719.    $ok = $ftp->_REST($where)
  720.     if $ok && $where;
  721.  
  722.    if($ok)
  723.     {
  724.      $ftp->command($cmd,@_);
  725.      $data = $ftp->_dataconn();
  726.      $ok = CMD_INFO == $ftp->response();
  727.      if($ok) 
  728.       {
  729.        $data->reading
  730.          if $data && $cmd =~ /RETR|LIST|NLST/;
  731.        return $data
  732.       }
  733.      $data->_close
  734.     if $data;
  735.     }
  736.    return undef;
  737.   }
  738.  
  739.  $ok = $ftp->port
  740.     unless (defined ${*$ftp}{'net_ftp_port'} ||
  741.             defined ${*$ftp}{'net_ftp_pasv'});
  742.  
  743.  $ok = $ftp->_REST($where)
  744.     if $ok && $where;
  745.  
  746.  return undef
  747.     unless $ok;
  748.  
  749.  $ftp->command($cmd,@_);
  750.  
  751.  return 1
  752.     if(defined ${*$ftp}{'net_ftp_pasv'});
  753.  
  754.  $ok = CMD_INFO == $ftp->response();
  755.  
  756.  return $ok 
  757.     unless exists ${*$ftp}{'net_ftp_intern_port'};
  758.  
  759.  return $ftp->_dataconn()
  760.     if $ok;
  761.  
  762.  close(delete ${*$ftp}{'net_ftp_listen'});
  763.  
  764.  return undef;
  765. }
  766.  
  767. ##
  768. ## Over-ride methods (Net::Cmd)
  769. ##
  770.  
  771. sub debug_text { $_[2] =~ /^(pass|resp)/i ? "$1 ....\n" : $_[2]; }
  772.  
  773. sub command
  774. {
  775.  my $ftp = shift;
  776.  
  777.  delete ${*$ftp}{'net_ftp_port'};
  778.  $ftp->SUPER::command(@_);
  779. }
  780.  
  781. sub response
  782. {
  783.  my $ftp = shift;
  784.  my $code = $ftp->SUPER::response();
  785.  
  786.  delete ${*$ftp}{'net_ftp_pasv'}
  787.     if ($code != CMD_MORE && $code != CMD_INFO);
  788.  
  789.  $code;
  790. }
  791.  
  792. sub parse_response
  793. {
  794.  return ($1, $2 eq "-")
  795.     if $_[1] =~ s/^(\d\d\d)(.?)//o;
  796.  
  797.  my $ftp = shift;
  798.  
  799.  # Darn MS FTP server is a load of CRAP !!!!
  800.  return ()
  801.     unless ${*$ftp}{'net_cmd_code'} + 0;
  802.  
  803.  (${*$ftp}{'net_cmd_code'},1);
  804. }
  805.  
  806. ##
  807. ## Allow 2 servers to talk directly
  808. ##
  809.  
  810. sub pasv_xfer
  811. {
  812.  my($sftp,$sfile,$dftp,$dfile,$unique) = @_;
  813.  
  814.  ($dfile = $sfile) =~ s#.*/##
  815.     unless(defined $dfile);
  816.  
  817.  my $port = $sftp->pasv or
  818.     return undef;
  819.  
  820.  unless($dftp->port($port) && $sftp->retr($sfile) &&
  821.         ($unique ? $dftp->stou($dfile) : $dftp->stor($dfile)) &&
  822.     $sftp->response() == CMD_INFO)
  823.   {
  824.    $sftp->abort;
  825.    $dftp->abort;
  826.    return undef;
  827.   }
  828.  
  829.  $dftp->pasv_wait($sftp);
  830. }
  831.  
  832. sub pasv_wait
  833. {
  834.  @_ == 2 or croak 'usage: $ftp->pasv_wait(NON_PASV_FTP)';
  835.  
  836.  my($ftp, $non_pasv) = @_;
  837.  my($file,$rin,$rout);
  838.  
  839.  vec($rin,fileno($ftp),1) = 1;
  840.  select($rout=$rin, undef, undef, undef);
  841.  
  842.  $ftp->response();
  843.  $non_pasv->response();
  844.  
  845.  return undef
  846.     unless $ftp->ok() && $non_pasv->ok();
  847.  
  848.  return $1
  849.     if $ftp->message =~ /unique file name:\s*(\S*)\s*\)/;
  850.  
  851.  return $1
  852.     if $non_pasv->message =~ /unique file name:\s*(\S*)\s*\)/;
  853.  
  854.  return 1;
  855. }
  856.  
  857. sub cmd { shift->command(@_)->response() }
  858.  
  859. ########################################
  860. #
  861. # RFC959 commands
  862. #
  863.  
  864. sub _ABOR { shift->command("ABOR")->response()     == CMD_OK }
  865. sub _CDUP { shift->command("CDUP")->response()     == CMD_OK }
  866. sub _NOOP { shift->command("NOOP")->response()     == CMD_OK }
  867. sub _PASV { shift->command("PASV")->response()     == CMD_OK }
  868. sub _QUIT { shift->command("QUIT")->response()     == CMD_OK }
  869. sub _DELE { shift->command("DELE",@_)->response() == CMD_OK }
  870. sub _CWD  { shift->command("CWD", @_)->response() == CMD_OK }
  871. sub _PORT { shift->command("PORT",@_)->response() == CMD_OK }
  872. sub _RMD  { shift->command("RMD", @_)->response() == CMD_OK }
  873. sub _MKD  { shift->command("MKD", @_)->response() == CMD_OK }
  874. sub _PWD  { shift->command("PWD", @_)->response() == CMD_OK }
  875. sub _TYPE { shift->command("TYPE",@_)->response() == CMD_OK }
  876. sub _RNTO { shift->command("RNTO",@_)->response() == CMD_OK }
  877. sub _ACCT { shift->command("ACCT",@_)->response() == CMD_OK }
  878. sub _RESP { shift->command("RESP",@_)->response() == CMD_OK }
  879. sub _MDTM { shift->command("MDTM",@_)->response() == CMD_OK }
  880. sub _SIZE { shift->command("SIZE",@_)->response() == CMD_OK }
  881. sub _HELP { shift->command("HELP",@_)->response() == CMD_OK }
  882. sub _APPE { shift->command("APPE",@_)->response() == CMD_INFO }
  883. sub _LIST { shift->command("LIST",@_)->response() == CMD_INFO }
  884. sub _NLST { shift->command("NLST",@_)->response() == CMD_INFO }
  885. sub _RETR { shift->command("RETR",@_)->response() == CMD_INFO }
  886. sub _STOR { shift->command("STOR",@_)->response() == CMD_INFO }
  887. sub _STOU { shift->command("STOU",@_)->response() == CMD_INFO }
  888. sub _RNFR { shift->command("RNFR",@_)->response() == CMD_MORE }
  889. sub _REST { shift->command("REST",@_)->response() == CMD_MORE }
  890. sub _USER { shift->command("user",@_)->response() } # A certain brain dead firewall :-)
  891. sub _PASS { shift->command("PASS",@_)->response() }
  892. sub _AUTH { shift->command("AUTH",@_)->response() }
  893.  
  894. sub _ALLO { shift->unsupported(@_) }
  895. sub _SMNT { shift->unsupported(@_) }
  896. sub _MODE { shift->unsupported(@_) }
  897. sub _SITE { shift->unsupported(@_) }
  898. sub _SYST { shift->unsupported(@_) }
  899. sub _STAT { shift->unsupported(@_) }
  900. sub _STRU { shift->unsupported(@_) }
  901. sub _REIN { shift->unsupported(@_) }
  902.  
  903. 1;
  904.  
  905. __END__
  906.  
  907. =head1 NAME
  908.  
  909. Net::FTP - FTP Client class
  910.  
  911. =head1 SYNOPSIS
  912.  
  913.     use Net::FTP;
  914.     
  915.     $ftp = Net::FTP->new("some.host.name");
  916.     $ftp->login("anonymous","me@here.there");
  917.     $ftp->cwd("/pub");
  918.     $ftp->get("that.file");
  919.     $ftp->quit;
  920.  
  921. =head1 DESCRIPTION
  922.  
  923. C<Net::FTP> is a class implementing a simple FTP client in Perl as
  924. described in RFC959.  It provides wrappers for a subset of the RFC959
  925. commands.
  926.  
  927. =head1 OVERVIEW
  928.  
  929. FTP stands for File Transfer Protocol.  It is a way of transferring
  930. files between networked machines.  The protocol defines a client
  931. (whose commands are provided by this module) and a server (not
  932. implemented in this module).  Communication is always initiated by the
  933. client, and the server responds with a message and a status code (and
  934. sometimes with data).
  935.  
  936. The FTP protocol allows files to be sent to or fetched from the
  937. server.  Each transfer involves a B<local file> (on the client) and a
  938. B<remote file> (on the server).  In this module, the same file name
  939. will be used for both local and remote if only one is specified.  This
  940. means that transferring remote file C</path/to/file> will try to put
  941. that file in C</path/to/file> locally, unless you specify a local file
  942. name.
  943.  
  944. The protocol also defines several standard B<translations> which the
  945. file can undergo during transfer.  These are ASCII, EBCDIC, binary,
  946. and byte.  ASCII is the default type, and indicates that the sender of
  947. files will translate the ends of lines to a standard representation
  948. which the receiver will then translate back into their local
  949. representation.  EBCDIC indicates the file being transferred is in
  950. EBCDIC format.  Binary (also known as image) format sends the data as
  951. a contiguous bit stream.  Byte format transfers the data as bytes, the
  952. values of which remain the same regardless of differences in byte size
  953. between the two machines (in theory - in practice you should only use
  954. this if you really know what you're doing).
  955.  
  956. =head1 CONSTRUCTOR
  957.  
  958. =over 4
  959.  
  960. =item new (HOST [,OPTIONS])
  961.  
  962. This is the constructor for a new Net::FTP object. C<HOST> is the
  963. name of the remote host to which a FTP connection is required.
  964.  
  965. C<OPTIONS> are passed in a hash like fashion, using key and value pairs.
  966. Possible options are:
  967.  
  968. B<Firewall> - The name of a machine which acts as a FTP firewall. This can be
  969. overridden by an environment variable C<FTP_FIREWALL>. If specified, and the
  970. given host cannot be directly connected to, then the
  971. connection is made to the firewall machine and the string C<@hostname> is
  972. appended to the login identifier. This kind of setup is also refered to
  973. as a ftp proxy.
  974.  
  975. B<Port> - The port number to connect to on the remote machine for the
  976. FTP connection
  977.  
  978. B<Timeout> - Set a timeout value (defaults to 120)
  979.  
  980. B<Debug> - debug level (see the debug method in L<Net::Cmd>)
  981.  
  982. B<Passive> - If set to I<true> then all data transfers will be done using 
  983. passive mode. This is required for some I<dumb> servers, and some
  984. firewall configurations.  This can also be set by the environment
  985. variable C<FTP_PASSIVE>.
  986.  
  987. If the constructor fails undef will be returned and an error message will
  988. be in $@
  989.  
  990. =back
  991.  
  992. =head1 METHODS
  993.  
  994. Unless otherwise stated all methods return either a I<true> or I<false>
  995. value, with I<true> meaning that the operation was a success. When a method
  996. states that it returns a value, failure will be returned as I<undef> or an
  997. empty list.
  998.  
  999. =over 4
  1000.  
  1001. =item login ([LOGIN [,PASSWORD [, ACCOUNT] ] ])
  1002.  
  1003. Log into the remote FTP server with the given login information. If
  1004. no arguments are given then the C<Net::FTP> uses the C<Net::Netrc>
  1005. package to lookup the login information for the connected host.
  1006. If no information is found then a login of I<anonymous> is used.
  1007. If no password is given and the login is I<anonymous> then the users
  1008. Email address will be used for a password.
  1009.  
  1010. If the connection is via a firewall then the C<authorize> method will
  1011. be called with no arguments.
  1012.  
  1013. =item authorize ( [AUTH [, RESP]])
  1014.  
  1015. This is a protocol used by some firewall ftp proxies. It is used
  1016. to authorise the user to send data out.  If both arguments are not specified
  1017. then C<authorize> uses C<Net::Netrc> to do a lookup.
  1018.  
  1019. =item type (TYPE [, ARGS])
  1020.  
  1021. This method will send the TYPE command to the remote FTP server
  1022. to change the type of data transfer. The return value is the previous
  1023. value.
  1024.  
  1025. =item ascii ([ARGS]) binary([ARGS]) ebcdic([ARGS]) byte([ARGS])
  1026.  
  1027. Synonyms for C<type> with the first arguments set correctly
  1028.  
  1029. B<NOTE> ebcdic and byte are not fully supported.
  1030.  
  1031. =item rename ( OLDNAME, NEWNAME )
  1032.  
  1033. Rename a file on the remote FTP server from C<OLDNAME> to C<NEWNAME>. This
  1034. is done by sending the RNFR and RNTO commands.
  1035.  
  1036. =item delete ( FILENAME )
  1037.  
  1038. Send a request to the server to delete C<FILENAME>.
  1039.  
  1040. =item cwd ( [ DIR ] )
  1041.  
  1042. Attempt to change directory to the directory given in C<$dir>.  If
  1043. C<$dir> is C<"..">, the FTP C<CDUP> command is used to attempt to
  1044. move up one directory. If no directory is given then an attempt is made
  1045. to change the directory to the root directory.
  1046.  
  1047. =item cdup ()
  1048.  
  1049. Change directory to the parent of the current directory.
  1050.  
  1051. =item pwd ()
  1052.  
  1053. Returns the full pathname of the current directory.
  1054.  
  1055. =item rmdir ( DIR )
  1056.  
  1057. Remove the directory with the name C<DIR>.
  1058.  
  1059. =item mkdir ( DIR [, RECURSE ])
  1060.  
  1061. Create a new directory with the name C<DIR>. If C<RECURSE> is I<true> then
  1062. C<mkdir> will attempt to create all the directories in the given path.
  1063.  
  1064. Returns the full pathname to the new directory.
  1065.  
  1066. =item ls ( [ DIR ] )
  1067.  
  1068. Get a directory listing of C<DIR>, or the current directory.
  1069.  
  1070. In an array context, returns a list of lines returned from the server. In
  1071. a scalar context, returns a reference to a list.
  1072.  
  1073. =item dir ( [ DIR ] )
  1074.  
  1075. Get a directory listing of C<DIR>, or the current directory in long format.
  1076.  
  1077. In an array context, returns a list of lines returned from the server. In
  1078. a scalar context, returns a reference to a list.
  1079.  
  1080. =item get ( REMOTE_FILE [, LOCAL_FILE [, WHERE]] )
  1081.  
  1082. Get C<REMOTE_FILE> from the server and store locally. C<LOCAL_FILE> may be
  1083. a filename or a filehandle. If not specified the the file will be stored in
  1084. the current directory with the same leafname as the remote file.
  1085.  
  1086. If C<WHERE> is given then the first C<WHERE> bytes of the file will
  1087. not be transfered, and the remaining bytes will be appended to
  1088. the local file if it already exists.
  1089.  
  1090. Returns C<LOCAL_FILE>, or the generated local file name if C<LOCAL_FILE>
  1091. is not given.
  1092.  
  1093. =item put ( LOCAL_FILE [, REMOTE_FILE ] )
  1094.  
  1095. Put a file on the remote server. C<LOCAL_FILE> may be a name or a filehandle.
  1096. If C<LOCAL_FILE> is a filehandle then C<REMOTE_FILE> must be specified. If
  1097. C<REMOTE_FILE> is not specified then the file will be stored in the current
  1098. directory with the same leafname as C<LOCAL_FILE>.
  1099.  
  1100. Returns C<REMOTE_FILE>, or the generated remote filename if C<REMOTE_FILE>
  1101. is not given.
  1102.  
  1103. B<NOTE>: If for some reason the transfer does not complete and an error is
  1104. returned then the contents that had been transfered will not be remove
  1105. automatically.
  1106.  
  1107. =item put_unique ( LOCAL_FILE [, REMOTE_FILE ] )
  1108.  
  1109. Same as put but uses the C<STOU> command.
  1110.  
  1111. Returns the name of the file on the server.
  1112.  
  1113. =item append ( LOCAL_FILE [, REMOTE_FILE ] )
  1114.  
  1115. Same as put but appends to the file on the remote server.
  1116.  
  1117. Returns C<REMOTE_FILE>, or the generated remote filename if C<REMOTE_FILE>
  1118. is not given.
  1119.  
  1120. =item unique_name ()
  1121.  
  1122. Returns the name of the last file stored on the server using the
  1123. C<STOU> command.
  1124.  
  1125. =item mdtm ( FILE )
  1126.  
  1127. Returns the I<modification time> of the given file
  1128.  
  1129. =item size ( FILE )
  1130.  
  1131. Returns the size in bytes for the given file as stored on the remote server.
  1132.  
  1133. B<NOTE>: The size reported is the size of the stored file on the remote server.
  1134. If the file is subsequently transfered from the server in ASCII mode
  1135. and the remote server and local machine have different ideas about
  1136. "End Of Line" then the size of file on the local machine after transfer
  1137. may be different.
  1138.  
  1139. =item supported ( CMD )
  1140.  
  1141. Returns TRUE if the remote server supports the given command.
  1142.  
  1143. =back
  1144.  
  1145. The following methods can return different results depending on
  1146. how they are called. If the user explicitly calls either
  1147. of the C<pasv> or C<port> methods then these methods will
  1148. return a I<true> or I<false> value. If the user does not
  1149. call either of these methods then the result will be a
  1150. reference to a C<Net::FTP::dataconn> based object.
  1151.  
  1152. =over 4
  1153.  
  1154. =item nlst ( [ DIR ] )
  1155.  
  1156. Send a C<NLST> command to the server, with an optional parameter.
  1157.  
  1158. =item list ( [ DIR ] )
  1159.  
  1160. Same as C<nlst> but using the C<LIST> command
  1161.  
  1162. =item retr ( FILE )
  1163.  
  1164. Begin the retrieval of a file called C<FILE> from the remote server.
  1165.  
  1166. =item stor ( FILE )
  1167.  
  1168. Tell the server that you wish to store a file. C<FILE> is the
  1169. name of the new file that should be created.
  1170.  
  1171. =item stou ( FILE )
  1172.  
  1173. Same as C<stor> but using the C<STOU> command. The name of the unique
  1174. file which was created on the server will be available via the C<unique_name>
  1175. method after the data connection has been closed.
  1176.  
  1177. =item appe ( FILE )
  1178.  
  1179. Tell the server that we want to append some data to the end of a file
  1180. called C<FILE>. If this file does not exist then create it.
  1181.  
  1182. =back
  1183.  
  1184. If for some reason you want to have complete control over the data connection,
  1185. this includes generating it and calling the C<response> method when required,
  1186. then the user can use these methods to do so.
  1187.  
  1188. However calling these methods only affects the use of the methods above that
  1189. can return a data connection. They have no effect on methods C<get>, C<put>,
  1190. C<put_unique> and those that do not require data connections.
  1191.  
  1192. =over 4
  1193.  
  1194. =item port ( [ PORT ] )
  1195.  
  1196. Send a C<PORT> command to the server. If C<PORT> is specified then it is sent
  1197. to the server. If not the a listen socket is created and the correct information
  1198. sent to the server.
  1199.  
  1200. =item pasv ()
  1201.  
  1202. Tell the server to go into passive mode. Returns the text that represents the
  1203. port on which the server is listening, this text is in a suitable form to
  1204. sent to another ftp server using the C<port> method.
  1205.  
  1206. =back
  1207.  
  1208. The following methods can be used to transfer files between two remote
  1209. servers, providing that these two servers can connect directly to each other.
  1210.  
  1211. =over 4
  1212.  
  1213. =item pasv_xfer ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
  1214.  
  1215. This method will do a file transfer between two remote ftp servers. If
  1216. C<DEST_FILE> is omitted then the leaf name of C<SRC_FILE> will be used.
  1217.  
  1218. =item pasv_xfer_unique ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
  1219.  
  1220. Like C<pasv_xfer> but the file is stored on the remote server using
  1221. the STOU command.
  1222.  
  1223. =item pasv_wait ( NON_PASV_SERVER )
  1224.  
  1225. This method can be used to wait for a transfer to complete between a passive
  1226. server and a non-passive server. The method should be called on the passive
  1227. server with the C<Net::FTP> object for the non-passive server passed as an
  1228. argument.
  1229.  
  1230. =item abort ()
  1231.  
  1232. Abort the current data transfer.
  1233.  
  1234. =item quit ()
  1235.  
  1236. Send the QUIT command to the remote FTP server and close the socket connection.
  1237.  
  1238. =back
  1239.  
  1240. =head2 Methods for the adventurous
  1241.  
  1242. C<Net::FTP> inherits from C<Net::Cmd> so methods defined in C<Net::Cmd> may
  1243. be used to send commands to the remote FTP server.
  1244.  
  1245. =over 4
  1246.  
  1247. =item quot (CMD [,ARGS])
  1248.  
  1249. Send a command, that Net::FTP does not directly support, to the remote
  1250. server and wait for a response.
  1251.  
  1252. Returns most significant digit of the response code.
  1253.  
  1254. B<WARNING> This call should only be used on commands that do not require
  1255. data connections. Misuse of this method can hang the connection.
  1256.  
  1257. =back
  1258.  
  1259. =head1 THE dataconn CLASS
  1260.  
  1261. Some of the methods defined in C<Net::FTP> return an object which will
  1262. be derived from this class.The dataconn class itself is derived from
  1263. the C<IO::Socket::INET> class, so any normal IO operations can be performed.
  1264. However the following methods are defined in the dataconn class and IO should
  1265. be performed using these.
  1266.  
  1267. =over 4
  1268.  
  1269. =item read ( BUFFER, SIZE [, TIMEOUT ] )
  1270.  
  1271. Read C<SIZE> bytes of data from the server and place it into C<BUFFER>, also
  1272. performing any <CRLF> translation necessary. C<TIMEOUT> is optional, if not
  1273. given the the timeout value from the command connection will be used.
  1274.  
  1275. Returns the number of bytes read before any <CRLF> translation.
  1276.  
  1277. =item write ( BUFFER, SIZE [, TIMEOUT ] )
  1278.  
  1279. Write C<SIZE> bytes of data from C<BUFFER> to the server, also
  1280. performing any <CRLF> translation necessary. C<TIMEOUT> is optional, if not
  1281. given the the timeout value from the command connection will be used.
  1282.  
  1283. Returns the number of bytes written before any <CRLF> translation.
  1284.  
  1285. =item abort ()
  1286.  
  1287. Abort the current data transfer.
  1288.  
  1289. =item close ()
  1290.  
  1291. Close the data connection and get a response from the FTP server. Returns
  1292. I<true> if the connection was closed successfully and the first digit of
  1293. the response from the server was a '2'.
  1294.  
  1295. =back
  1296.  
  1297. =head1 UNIMPLEMENTED
  1298.  
  1299. The following RFC959 commands have not been implemented:
  1300.  
  1301. =over 4
  1302.  
  1303. =item B<ALLO>
  1304.  
  1305. Allocates storage for the file to be transferred.
  1306.  
  1307. =item B<SMNT>
  1308.  
  1309. Mount a different file system structure without changing login or
  1310. accounting information.
  1311.  
  1312. =item B<HELP>
  1313.  
  1314. Ask the server for "helpful information" (that's what the RFC says) on
  1315. the commands it accepts.
  1316.  
  1317. =item B<MODE>
  1318.  
  1319. Specifies transfer mode (stream, block or compressed) for file to be
  1320. transferred.
  1321.  
  1322. =item B<SITE>
  1323.  
  1324. Request remote server site parameters.
  1325.  
  1326. =item B<SYST>
  1327.  
  1328. Request remote server system identification.
  1329.  
  1330. =item B<STAT>
  1331.  
  1332. Request remote server status.
  1333.  
  1334. =item B<STRU>
  1335.  
  1336. Specifies file structure for file to be transferred.
  1337.  
  1338. =item B<REIN>
  1339.  
  1340. Reinitialize the connection, flushing all I/O and account information.
  1341.  
  1342. =back
  1343.  
  1344. =head1 REPORTING BUGS
  1345.  
  1346. When reporting bugs/problems please include as much information as possible.
  1347. It may be difficult for me to reproduce the problem as almost every setup
  1348. is different.
  1349.  
  1350. A small script which yields the problem will probably be of help. It would
  1351. also be useful if this script was run with the extra options C<Debug => 1>
  1352. passed to the constructor, and the output sent with the bug report. If you
  1353. cannot include a small script then please include a Debug trace from a
  1354. run of your program which does yield the problem.
  1355.  
  1356. =head1 AUTHOR
  1357.  
  1358. Graham Barr <gbarr@pobox.com>
  1359.  
  1360. =head1 SEE ALSO
  1361.  
  1362. L<Net::Netrc>
  1363. L<Net::Cmd>
  1364.  
  1365. ftp(1), ftpd(8), RFC 959
  1366. http://www.cis.ohio-state.edu/htbin/rfc/rfc959.html
  1367.  
  1368. =head1 CREDITS
  1369.  
  1370. Henry Gabryjelski <henryg@WPI.EDU> - for the suggestion of creating directories
  1371. recursively.
  1372.  
  1373. Nathan Torkington <gnat@frii.com> - for some input on the documentation.
  1374.  
  1375. Roderick Schertler <roderick@gate.net> - for various inputs
  1376.  
  1377. =head1 COPYRIGHT
  1378.  
  1379. Copyright (c) 1995-1997 Graham Barr. All rights reserved.
  1380. This program is free software; you can redistribute it and/or modify it
  1381. under the same terms as Perl itself.
  1382.  
  1383. =cut
  1384.