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