<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Net::FTP.pm
#
# Copyright (c) 1995-8 Graham Barr &lt;gbarr@pobox.com&gt;. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# Documentation (at end) improved 1996 by Nathan Torkington &lt;gnat@frii.com&gt;.

package Net::FTP;

require 5.001;

use strict;
use vars qw(@ISA $VERSION);
use Carp;

use Socket 1.3;
use IO::Socket;
use Time::Local;
use Net::Cmd;
use Net::Config;
use Fcntl qw(O_WRONLY O_RDONLY O_APPEND O_CREAT O_TRUNC);
# use AutoLoader qw(AUTOLOAD);

$VERSION = "2.65"; # $Id: //depot/libnet/Net/FTP.pm#68 $
@ISA     = qw(Exporter Net::Cmd IO::Socket::INET);

# Someday I will "use constant", when I am not bothered to much about
# compatability with older releases of perl

use vars qw($TELNET_IAC $TELNET_IP $TELNET_DM);
($TELNET_IAC,$TELNET_IP,$TELNET_DM) = (255,244,242);

# Name is too long for AutoLoad, it clashes with pasv_xfer
sub pasv_xfer_unique {
    my($sftp,$sfile,$dftp,$dfile) = @_;
    $sftp-&gt;pasv_xfer($sfile,$dftp,$dfile,1);
}

BEGIN {
  # make a constant so code is fast'ish
  my $is_os390 = $^O eq 'os390';
  *trEBCDIC = sub () { $is_os390 }
}

1;
# Having problems with AutoLoader
#__END__

sub new
{
 my $pkg  = shift;
 my $peer = shift;
 my %arg  = @_; 

 my $host = $peer;
 my $fire = undef;
 my $fire_type = undef;

 if(exists($arg{Firewall}) || Net::Config-&gt;requires_firewall($peer))
  {
   $fire = $arg{Firewall}
	|| $ENV{FTP_FIREWALL}
	|| $NetConfig{ftp_firewall}
	|| undef;

   if(defined $fire)
    {
     $peer = $fire;
     delete $arg{Port};
	 $fire_type = $arg{FirewallType}
	 || $ENV{FTP_FIREWALL_TYPE}
	 || undef;
    }
  }

 my $ftp = $pkg-&gt;SUPER::new(PeerAddr =&gt; $peer, 
			    PeerPort =&gt; $arg{Port} || 'ftp(21)',
			    Proto    =&gt; 'tcp',
			    Timeout  =&gt; defined $arg{Timeout}
						? $arg{Timeout}
						: 120
			   ) or return undef;

 ${*$ftp}{'net_ftp_host'}     = $host;		# Remote hostname
 ${*$ftp}{'net_ftp_type'}     = 'A';		# ASCII/binary/etc mode
 ${*$ftp}{'net_ftp_blksize'}  = abs($arg{'BlockSize'} || 10240);

 ${*$ftp}{'net_ftp_firewall'} = $fire
	if(defined $fire);
 ${*$ftp}{'net_ftp_firewall_type'} = $fire_type
	if(defined $fire_type);

 ${*$ftp}{'net_ftp_passive'} = int
	exists $arg{Passive}
	    ? $arg{Passive}
	    : exists $ENV{FTP_PASSIVE}
		? $ENV{FTP_PASSIVE}
		: defined $fire
		    ? $NetConfig{ftp_ext_passive}
		    : $NetConfig{ftp_int_passive};	# Whew! :-)

 $ftp-&gt;hash(exists $arg{Hash} ? $arg{Hash} : 0, 1024);

 $ftp-&gt;autoflush(1);

 $ftp-&gt;debug(exists $arg{Debug} ? $arg{Debug} : undef);

 unless ($ftp-&gt;response() == CMD_OK)
  {
   $ftp-&gt;close();
   $@ = $ftp-&gt;message;
   undef $ftp;
  }

 $ftp;
}

##
## User interface methods
##

sub hash {
    my $ftp = shift;		# self

    my($h,$b) = @_;
    unless($h) {
      delete ${*$ftp}{'net_ftp_hash'};
      return [\*STDERR,0];
    }
    ($h,$b) = (ref($h)? $h : \*STDERR, $b || 1024);
    select((select($h), $|=1)[0]);
    $b = 512 if $b &lt; 512;
    ${*$ftp}{'net_ftp_hash'} = [$h, $b];
}        

sub quit
{
 my $ftp = shift;

 $ftp-&gt;_QUIT;
 $ftp-&gt;close;
}

sub DESTROY {}

sub ascii  { shift-&gt;type('A',@_); }
sub binary { shift-&gt;type('I',@_); }

sub ebcdic
{
 carp "TYPE E is unsupported, shall default to I";
 shift-&gt;type('E',@_);
}

sub byte
{
 carp "TYPE L is unsupported, shall default to I";
 shift-&gt;type('L',@_);
}

# Allow the user to send a command directly, BE CAREFUL !!

sub quot
{ 
 my $ftp = shift;
 my $cmd = shift;

 $ftp-&gt;command( uc $cmd, @_);
 $ftp-&gt;response();
}

sub site
{
 my $ftp = shift;

 $ftp-&gt;command("SITE", @_);
 $ftp-&gt;response();
}

sub mdtm
{
 my $ftp  = shift;
 my $file = shift;

 # Server Y2K bug workaround
 #
 # sigh; some idiotic FTP servers use ("19%d",tm.tm_year) instead of 
 # ("%d",tm.tm_year+1900).  This results in an extra digit in the
 # string returned. To account for this we allow an optional extra
 # digit in the year. Then if the first two digits are 19 we use the
 # remainder, otherwise we subtract 1900 from the whole year.

 $ftp-&gt;_MDTM($file) &amp;&amp; $ftp-&gt;message =~ /((\d\d)(\d\d\d?))(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/
    ? timegm($8,$7,$6,$5,$4-1,$2 eq '19' ? $3 : ($1-1900))
    : undef;
}

sub size {
  my $ftp  = shift;
  my $file = shift;
  my $io;
  if($ftp-&gt;supported("SIZE")) {
    return $ftp-&gt;_SIZE($file)
	? ($ftp-&gt;message =~ /(\d+)$/)[0]
	: undef;
 }
 elsif($ftp-&gt;supported("STAT")) {
   my @msg;
   return undef
       unless $ftp-&gt;_STAT($file) &amp;&amp; (@msg = $ftp-&gt;message) == 3;
   my $line;
   foreach $line (@msg) {
     return (split(/\s+/,$line))[4]
	 if $line =~ /^[-rwx]{10}/
   }
 }
 else {
   my @files = $ftp-&gt;dir($file);
   if(@files) {
     return (split(/\s+/,$1))[4]
	 if $files[0] =~ /^([-rwx]{10}.*)$/;
   }
 }
 undef;
}

sub login {
  my($ftp,$user,$pass,$acct) = @_;
  my($ok,$ruser,$fwtype);

  unless (defined $user) {
    require Net::Netrc;

    my $rc = Net::Netrc-&gt;lookup(${*$ftp}{'net_ftp_host'});

    ($user,$pass,$acct) = $rc-&gt;lpa()
	 if ($rc);
   }

  $user ||= "anonymous";
  $ruser = $user;

  $fwtype = ${*$ftp}{'net_ftp_firewall_type'}
  || $NetConfig{'ftp_firewall_type'}
  || 0;

  if ($fwtype &amp;&amp; defined ${*$ftp}{'net_ftp_firewall'}) {
    if ($fwtype == 1 || $fwtype == 7) {
      $user .= '@' . ${*$ftp}{'net_ftp_host'};
    }
    else {
      require Net::Netrc;

      my $rc = Net::Netrc-&gt;lookup(${*$ftp}{'net_ftp_firewall'});

      my($fwuser,$fwpass,$fwacct) = $rc ? $rc-&gt;lpa() : ();

      if ($fwtype == 5) {
	$user = join('@',$user,$fwuser,${*$ftp}{'net_ftp_host'});
	$pass = $pass . '@' . $fwpass;
      }
      else {
	if ($fwtype == 2) {
	  $user .= '@' . ${*$ftp}{'net_ftp_host'};
	}
	elsif ($fwtype == 6) {
	  $fwuser .= '@' . ${*$ftp}{'net_ftp_host'};
	}

	$ok = $ftp-&gt;_USER($fwuser);

	return 0 unless $ok == CMD_OK || $ok == CMD_MORE;

	$ok = $ftp-&gt;_PASS($fwpass || "");

	return 0 unless $ok == CMD_OK || $ok == CMD_MORE;

	$ok = $ftp-&gt;_ACCT($fwacct)
	  if defined($fwacct);

	if ($fwtype == 3) {
          $ok = $ftp-&gt;command("SITE",${*$ftp}{'net_ftp_host'})-&gt;response;
	}
	elsif ($fwtype == 4) {
          $ok = $ftp-&gt;command("OPEN",${*$ftp}{'net_ftp_host'})-&gt;response;
	}

	return 0 unless $ok == CMD_OK || $ok == CMD_MORE;
      }
    }
  }

  $ok = $ftp-&gt;_USER($user);

  # Some dumb firewalls don't prefix the connection messages
  $ok = $ftp-&gt;response()
	 if ($ok == CMD_OK &amp;&amp; $ftp-&gt;code == 220 &amp;&amp; $user =~ /\@/);

  if ($ok == CMD_MORE) {
    unless(defined $pass) {
      require Net::Netrc;

      my $rc = Net::Netrc-&gt;lookup(${*$ftp}{'net_ftp_host'}, $ruser);

      ($ruser,$pass,$acct) = $rc-&gt;lpa()
	 if ($rc);

      $pass = '-anonymous@'
         if (!defined $pass &amp;&amp; (!defined($ruser) || $ruser =~ /^anonymous/o));
    }

    $ok = $ftp-&gt;_PASS($pass || "");
  }

  $ok = $ftp-&gt;_ACCT($acct)
	 if (defined($acct) &amp;&amp; ($ok == CMD_MORE || $ok == CMD_OK));

  if ($fwtype == 7 &amp;&amp; $ok == CMD_OK &amp;&amp; defined ${*$ftp}{'net_ftp_firewall'}) {
    my($f,$auth,$resp) = _auth_id($ftp);
    $ftp-&gt;authorize($auth,$resp) if defined($resp);
  }

  $ok == CMD_OK;
}

sub account
{
 @_ == 2 or croak 'usage: $ftp-&gt;account( ACCT )';
 my $ftp = shift;
 my $acct = shift;
 $ftp-&gt;_ACCT($acct) == CMD_OK;
}

sub _auth_id {
 my($ftp,$auth,$resp) = @_;

 unless(defined $resp)
  {
   require Net::Netrc;

   $auth ||= eval { (getpwuid($&gt;))[0] } || $ENV{NAME};

   my $rc = Net::Netrc-&gt;lookup(${*$ftp}{'net_ftp_firewall'}, $auth)
        || Net::Netrc-&gt;lookup(${*$ftp}{'net_ftp_firewall'});

   ($auth,$resp) = $rc-&gt;lpa()
     if ($rc);
  }
  ($ftp,$auth,$resp);
}

sub authorize
{
 @_ &gt;= 1 || @_ &lt;= 3 or croak 'usage: $ftp-&gt;authorize( [AUTH [, RESP]])';

 my($ftp,$auth,$resp) = &amp;_auth_id;

 my $ok = $ftp-&gt;_AUTH($auth || "");

 $ok = $ftp-&gt;_RESP($resp || "")
	if ($ok == CMD_MORE);

 $ok == CMD_OK;
}

sub rename
{
 @_ == 3 or croak 'usage: $ftp-&gt;rename(FROM, TO)';

 my($ftp,$from,$to) = @_;

 $ftp-&gt;_RNFR($from)
    &amp;&amp; $ftp-&gt;_RNTO($to);
}

sub type
{
 my $ftp = shift;
 my $type = shift;
 my $oldval = ${*$ftp}{'net_ftp_type'};

 return $oldval
	unless (defined $type);

 return undef
	unless ($ftp-&gt;_TYPE($type,@_));

 ${*$ftp}{'net_ftp_type'} = join(" ",$type,@_);

 $oldval;
}

sub abort
{
 my $ftp = shift;

 send($ftp,pack("CCC", $TELNET_IAC, $TELNET_IP, $TELNET_IAC),MSG_OOB);

 $ftp-&gt;command(pack("C",$TELNET_DM) . "ABOR");

 ${*$ftp}{'net_ftp_dataconn'}-&gt;close()
    if defined ${*$ftp}{'net_ftp_dataconn'};

 $ftp-&gt;response();

 $ftp-&gt;status == CMD_OK;
}

sub get
{
 my($ftp,$remote,$local,$where) = @_;

 my($loc,$len,$buf,$resp,$data);
 local *FD;

 my $localfd = ref($local) || ref(\$local) eq "GLOB";

 ($local = $remote) =~ s#^.*/##
	unless(defined $local);

 croak("Bad remote filename '$remote'\n")
	if $remote =~ /[\r\n]/s;

 ${*$ftp}{'net_ftp_rest'} = $where
	if ($where);

 delete ${*$ftp}{'net_ftp_port'};
 delete ${*$ftp}{'net_ftp_pasv'};

 $data = $ftp-&gt;retr($remote) or
	return undef;

 if($localfd)
  {
   $loc = $local;
  }
 else
  {
   $loc = \*FD;

   unless(sysopen($loc, $local, O_CREAT | O_WRONLY | ($where ? O_APPEND : O_TRUNC)))
    {
     carp "Cannot open Local file $local: $!\n";
     $data-&gt;abort;
     return undef;
    }
  }

 if($ftp-&gt;type eq 'I' &amp;&amp; !binmode($loc))
  {
   carp "Cannot binmode Local file $local: $!\n";
   $data-&gt;abort;
   close($loc) unless $localfd;
   return undef;
  }

 $buf = '';
 my($count,$hashh,$hashb,$ref) = (0);

 ($hashh,$hashb) = @$ref
   if($ref = ${*$ftp}{'net_ftp_hash'});

 my $blksize = ${*$ftp}{'net_ftp_blksize'};

 while(1)
  {
   last unless $len = $data-&gt;read($buf,$blksize);

   if (trEBCDIC &amp;&amp; $ftp-&gt;type ne 'I')
    {
     $buf = $ftp-&gt;toebcdic($buf);
     $len = length($buf);
    }

   if($hashh) {
    $count += $len;
    print $hashh "#" x (int($count / $hashb));
    $count %= $hashb;
   }
   my $written = syswrite($loc,$buf,$len);
   unless(defined($written) &amp;&amp; $written == $len)
    {
     carp "Cannot write to Local file $local: $!\n";
     $data-&gt;abort;
     close($loc)
        unless $localfd;
     return undef;
    }
  }

 print $hashh "\n" if $hashh;

 unless ($localfd)
  {
   unless (close($loc))
    {
     carp "Cannot close file $local (perhaps disk space) $!\n";
     return undef;
    }
  }

 unless ($data-&gt;close()) # implied $ftp-&gt;response
  {
   carp "Unable to close datastream";
   return undef;
  }

 return $local;
}

sub cwd
{
 @_ == 1 || @_ == 2 or croak 'usage: $ftp-&gt;cwd( [ DIR ] )';

 my($ftp,$dir) = @_;

 $dir = "/" unless defined($dir) &amp;&amp; $dir =~ /\S/;

 $dir eq ".."
    ? $ftp-&gt;_CDUP()
    : $ftp-&gt;_CWD($dir);
}

sub cdup
{
 @_ == 1 or croak 'usage: $ftp-&gt;cdup()';
 $_[0]-&gt;_CDUP;
}

sub pwd
{
 @_ == 1 || croak 'usage: $ftp-&gt;pwd()';
 my $ftp = shift;

 $ftp-&gt;_PWD();
 $ftp-&gt;_extract_path;
}

# rmdir( $ftp, $dir, [ $recurse ] )
#
# Removes $dir on remote host via FTP.
# $ftp is handle for remote host
#
# If $recurse is TRUE, the directory and deleted recursively.
# This means all of its contents and subdirectories.
#
# Initial version contributed by Dinkum Software
#
sub rmdir
{
    @_ == 2 || @_ == 3 or croak('usage: $ftp-&gt;rmdir( DIR [, RECURSE ] )');

    # Pick off the args
    my ($ftp, $dir, $recurse) = @_ ;
    my $ok;

    return $ok
	if $ok = $ftp-&gt;_RMD( $dir ) or !$recurse;

    # Try to delete the contents
    # Get a list of all the files in the directory
    my $filelist = $ftp-&gt;ls($dir);

    return undef
	unless $filelist &amp;&amp; @$filelist; # failed, it is probably not a directory

    # Go thru and delete each file or the directory
    my $file;
    foreach $file (map { m,/, ? $_ : "$dir/$_" } @$filelist)
    {
	next  # successfully deleted the file
	    if $ftp-&gt;delete($file);

	# Failed to delete it, assume its a directory
	# Recurse and ignore errors, the final rmdir() will
	# fail on any errors here
	return $ok
	    unless $ok = $ftp-&gt;rmdir($file, 1) ;
    }

    # Directory should be empty
    # Try to remove the directory again
    # Pass results directly to caller
    # If any of the prior deletes failed, this
    # rmdir() will fail because directory is not empty
    return $ftp-&gt;_RMD($dir) ;
}

sub restart
{
  @_ == 2 || croak 'usage: $ftp-&gt;restart( BYTE_OFFSET )';

  my($ftp,$where) = @_;

  ${*$ftp}{'net_ftp_rest'} = $where;

  return undef;
}


sub mkdir
{
 @_ == 2 || @_ == 3 or croak 'usage: $ftp-&gt;mkdir( DIR [, RECURSE ] )';

 my($ftp,$dir,$recurse) = @_;

 $ftp-&gt;_MKD($dir) || $recurse or
    return undef;

 my $path = $dir;

 unless($ftp-&gt;ok)
  {
   my @path = split(m#(?=/+)#, $dir);

   $path = "";

   while(@path)
    {
     $path .= shift @path;

     $ftp-&gt;_MKD($path);

     $path = $ftp-&gt;_extract_path($path);
    }

   # If the creation of the last element was not sucessful, see if we
   # can cd to it, if so then return path

   unless($ftp-&gt;ok)
    {
     my($status,$message) = ($ftp-&gt;status,$ftp-&gt;message);
     my $pwd = $ftp-&gt;pwd;

     if($pwd &amp;&amp; $ftp-&gt;cwd($dir))
      {
       $path = $dir;
       $ftp-&gt;cwd($pwd);
      }
     else
      {
       undef $path;
      }
     $ftp-&gt;set_status($status,$message);
    }
  }

 $path;
}

sub delete
{
 @_ == 2 || croak 'usage: $ftp-&gt;delete( FILENAME )';

 $_[0]-&gt;_DELE($_[1]);
}

sub put        { shift-&gt;_store_cmd("stor",@_) }
sub put_unique { shift-&gt;_store_cmd("stou",@_) }
sub append     { shift-&gt;_store_cmd("appe",@_) }

sub nlst { shift-&gt;_data_cmd("NLST",@_) }
sub list { shift-&gt;_data_cmd("LIST",@_) }
sub retr { shift-&gt;_data_cmd("RETR",@_) }
sub stor { shift-&gt;_data_cmd("STOR",@_) }
sub stou { shift-&gt;_data_cmd("STOU",@_) }
sub appe { shift-&gt;_data_cmd("APPE",@_) }

sub _store_cmd 
{
 my($ftp,$cmd,$local,$remote) = @_;
 my($loc,$sock,$len,$buf);
 local *FD;

 my $localfd = ref($local) || ref(\$local) eq "GLOB";

 unless(defined $remote)
  {
   croak 'Must specify remote filename with stream input'
	if $localfd;

   require File::Basename;
   $remote = File::Basename::basename($local);
  }

 croak("Bad remote filename '$remote'\n")
	if $remote =~ /[\r\n]/s;

 if($localfd)
  {
   $loc = $local;
  }
 else
  {
   $loc = \*FD;

   unless(sysopen($loc, $local, O_RDONLY))
    {
     carp "Cannot open Local file $local: $!\n";
     return undef;
    }
  }

 if($ftp-&gt;type eq 'I' &amp;&amp; !binmode($loc))
  {
   carp "Cannot binmode Local file $local: $!\n";
   return undef;
  }

 delete ${*$ftp}{'net_ftp_port'};
 delete ${*$ftp}{'net_ftp_pasv'};

 $sock = $ftp-&gt;_data_cmd($cmd, $remote) or 
	return undef;

 my $blksize = ${*$ftp}{'net_ftp_blksize'};

 my($count,$hashh,$hashb,$ref) = (0);

 ($hashh,$hashb) = @$ref
   if($ref = ${*$ftp}{'net_ftp_hash'});

 while(1)
  {
   last unless $len = sysread($loc,$buf="",$blksize);

   if (trEBCDIC &amp;&amp; $ftp-&gt;type ne 'I')
    {
     $buf = $ftp-&gt;toascii($buf); 
     $len = length($buf);
    }

   if($hashh) {
    $count += $len;
    print $hashh "#" x (int($count / $hashb));
    $count %= $hashb;
   }

   my $wlen;
   unless(defined($wlen = $sock-&gt;write($buf,$len)) &amp;&amp; $wlen == $len)
    {
     $sock-&gt;abort;
     close($loc)
	unless $localfd;
     print $hashh "\n" if $hashh;
     return undef;
    }
  }

 print $hashh "\n" if $hashh;

 close($loc)
	unless $localfd;

 $sock-&gt;close() or
	return undef;

 if ('STOU' eq uc $cmd and $ftp-&gt;message =~ m/unique\s+file\s*name\s*:\s*(.*)\)|"(.*)"/)
  {
   require File::Basename;
   $remote = File::Basename::basename($+) 
  }

 return $remote;
}

sub port
{
 @_ == 1 || @_ == 2 or croak 'usage: $ftp-&gt;port([PORT])';

 my($ftp,$port) = @_;
 my $ok;

 delete ${*$ftp}{'net_ftp_intern_port'};

 unless(defined $port)
  {
   # create a Listen socket at same address as the command socket

   ${*$ftp}{'net_ftp_listen'} ||= IO::Socket::INET-&gt;new(Listen    =&gt; 5,
				    	    	        Proto     =&gt; 'tcp',
							Timeout   =&gt; $ftp-&gt;timeout,
							LocalAddr =&gt; $ftp-&gt;sockhost,
				    	    	       );

   my $listen = ${*$ftp}{'net_ftp_listen'};

   my($myport, @myaddr) = ($listen-&gt;sockport, split(/\./,$listen-&gt;sockhost));

   $port = join(',', @myaddr, $myport &gt;&gt; 8, $myport &amp; 0xff);

   ${*$ftp}{'net_ftp_intern_port'} = 1;
  }

 $ok = $ftp-&gt;_PORT($port);

 ${*$ftp}{'net_ftp_port'} = $port;

 $ok;
}

sub ls  { shift-&gt;_list_cmd("NLST",@_); }
sub dir { shift-&gt;_list_cmd("LIST",@_); }

sub pasv
{
 @_ == 1 or croak 'usage: $ftp-&gt;pasv()';

 my $ftp = shift;

 delete ${*$ftp}{'net_ftp_intern_port'};

 $ftp-&gt;_PASV &amp;&amp; $ftp-&gt;message =~ /(\d+(,\d+)+)/
    ? ${*$ftp}{'net_ftp_pasv'} = $1
    : undef;    
}

sub unique_name
{
 my $ftp = shift;
 ${*$ftp}{'net_ftp_unique'} || undef;
}

sub supported {
    @_ == 2 or croak 'usage: $ftp-&gt;supported( CMD )';
    my $ftp = shift;
    my $cmd = uc shift;
    my $hash = ${*$ftp}{'net_ftp_supported'} ||= {};

    return $hash-&gt;{$cmd}
        if exists $hash-&gt;{$cmd};

    return $hash-&gt;{$cmd} = 0
	unless $ftp-&gt;_HELP($cmd);

    my $text = $ftp-&gt;message;
    if($text =~ /following\s+commands/i) {
	$text =~ s/^.*\n//;
        while($text =~ /(\*?)(\w+)(\*?)/sg) {
            $hash-&gt;{"\U$2"} = !length("$1$3");
        }
    }
    else {
	$hash-&gt;{$cmd} = $text !~ /unimplemented/i;
    }

    $hash-&gt;{$cmd} ||= 0;
}

##
## Deprecated methods
##

sub lsl
{
 carp "Use of Net::FTP::lsl deprecated, use 'dir'"
    if $^W;
 goto &amp;dir;
}

sub authorise
{
 carp "Use of Net::FTP::authorise deprecated, use 'authorize'"
    if $^W;
 goto &amp;authorize;
}


##
## Private methods
##

sub _extract_path
{
 my($ftp, $path) = @_;

 # This tries to work both with and without the quote doubling
 # convention (RFC 959 requires it, but the first 3 servers I checked
 # didn't implement it).  It will fail on a server which uses a quote in
 # the message which isn't a part of or surrounding the path.
 $ftp-&gt;ok &amp;&amp;
    $ftp-&gt;message =~ /(?:^|\s)\"(.*)\"(?:$|\s)/ &amp;&amp;
    ($path = $1) =~ s/\"\"/\"/g;

 $path;
}

##
## Communication methods
##

sub _dataconn
{
 my $ftp = shift;
 my $data = undef;
 my $pkg = "Net::FTP::" . $ftp-&gt;type;

 eval "require " . $pkg;

 $pkg =~ s/ /_/g;

 delete ${*$ftp}{'net_ftp_dataconn'};

 if(defined ${*$ftp}{'net_ftp_pasv'})
  {
   my @port = split(/,/,${*$ftp}{'net_ftp_pasv'});

   $data = $pkg-&gt;new(PeerAddr =&gt; join(".",@port[0..3]),
    	    	     PeerPort =&gt; $port[4] * 256 + $port[5],
    	    	     Proto    =&gt; 'tcp'
    	    	    );
  }
 elsif(defined ${*$ftp}{'net_ftp_listen'})
  {
   $data = ${*$ftp}{'net_ftp_listen'}-&gt;accept($pkg);
   close(delete ${*$ftp}{'net_ftp_listen'});
  }

 if($data)
  {
   ${*$data} = "";
   $data-&gt;timeout($ftp-&gt;timeout);
   ${*$ftp}{'net_ftp_dataconn'} = $data;
   ${*$data}{'net_ftp_cmd'} = $ftp;
   ${*$data}{'net_ftp_blksize'} = ${*$ftp}{'net_ftp_blksize'};
  }

 $data;
}

sub _list_cmd
{
 my $ftp = shift;
 my $cmd = uc shift;

 delete ${*$ftp}{'net_ftp_port'};
 delete ${*$ftp}{'net_ftp_pasv'};

 my $data = $ftp-&gt;_data_cmd($cmd,@_);

 return
	unless(defined $data);

 require Net::FTP::A;
 bless $data, "Net::FTP::A"; # Force ASCII mode

 my $databuf = '';
 my $buf = '';
 my $blksize = ${*$ftp}{'net_ftp_blksize'};

 while($data-&gt;read($databuf,$blksize)) {
   $buf .= $databuf;
 }

 my $list = [ split(/\n/,$buf) ];

 $data-&gt;close();

 if (trEBCDIC)
  {
   for (@$list) { $_ = $ftp-&gt;toebcdic($_) }
  }

 wantarray ? @{$list}
           : $list;
}

sub _data_cmd
{
 my $ftp = shift;
 my $cmd = uc shift;
 my $ok = 1;
 my $where = delete ${*$ftp}{'net_ftp_rest'} || 0;
 my $arg;

 for $arg (@_) {
   croak("Bad argument '$arg'\n")
	if $arg =~ /[\r\n]/s;
 }

 if(${*$ftp}{'net_ftp_passive'} &amp;&amp;
     !defined ${*$ftp}{'net_ftp_pasv'} &amp;&amp;
     !defined ${*$ftp}{'net_ftp_port'})
  {
   my $data = undef;

   $ok = defined $ftp-&gt;pasv;
   $ok = $ftp-&gt;_REST($where)
	if $ok &amp;&amp; $where;

   if($ok)
    {
     $ftp-&gt;command($cmd,@_);
     $data = $ftp-&gt;_dataconn();
     $ok = CMD_INFO == $ftp-&gt;response();
     if($ok) 
      {
       $data-&gt;reading
         if $data &amp;&amp; $cmd =~ /RETR|LIST|NLST/;
       return $data
      }
     $data-&gt;_close
	if $data;
    }
   return undef;
  }

 $ok = $ftp-&gt;port
    unless (defined ${*$ftp}{'net_ftp_port'} ||
            defined ${*$ftp}{'net_ftp_pasv'});

 $ok = $ftp-&gt;_REST($where)
    if $ok &amp;&amp; $where;

 return undef
    unless $ok;

 $ftp-&gt;command($cmd,@_);

 return 1
    if(defined ${*$ftp}{'net_ftp_pasv'});

 $ok = CMD_INFO == $ftp-&gt;response();

 return $ok 
    unless exists ${*$ftp}{'net_ftp_intern_port'};

 if($ok) {
   my $data = $ftp-&gt;_dataconn();

   $data-&gt;reading
         if $data &amp;&amp; $cmd =~ /RETR|LIST|NLST/;

   return $data;
 }


 close(delete ${*$ftp}{'net_ftp_listen'});

 return undef;
}

##
## Over-ride methods (Net::Cmd)
##

sub debug_text { $_[2] =~ /^(pass|resp|acct)/i ? "$1 ....\n" : $_[2]; }

sub command
{
 my $ftp = shift;

 delete ${*$ftp}{'net_ftp_port'};
 $ftp-&gt;SUPER::command(@_);
}

sub response
{
 my $ftp = shift;
 my $code = $ftp-&gt;SUPER::response();

 delete ${*$ftp}{'net_ftp_pasv'}
    if ($code != CMD_MORE &amp;&amp; $code != CMD_INFO);

 $code;
}

sub parse_response
{
 return ($1, $2 eq "-")
    if $_[1] =~ s/^(\d\d\d)(.?)//o;

 my $ftp = shift;

 # Darn MS FTP server is a load of CRAP !!!!
 return ()
	unless ${*$ftp}{'net_cmd_code'} + 0;

 (${*$ftp}{'net_cmd_code'},1);
}

##
## Allow 2 servers to talk directly
##

sub pasv_xfer {
    my($sftp,$sfile,$dftp,$dfile,$unique) = @_;

    ($dfile = $sfile) =~ s#.*/##
	unless(defined $dfile);

    my $port = $sftp-&gt;pasv or
	return undef;

    $dftp-&gt;port($port) or
	return undef;

    return undef
	unless($unique ? $dftp-&gt;stou($dfile) : $dftp-&gt;stor($dfile));

    unless($sftp-&gt;retr($sfile) &amp;&amp; $sftp-&gt;response == CMD_INFO) {
	$sftp-&gt;retr($sfile);
	$dftp-&gt;abort;
	$dftp-&gt;response();
	return undef;
    }

    $dftp-&gt;pasv_wait($sftp);
}

sub pasv_wait
{
 @_ == 2 or croak 'usage: $ftp-&gt;pasv_wait(NON_PASV_FTP)';

 my($ftp, $non_pasv) = @_;
 my($file,$rin,$rout);

 vec($rin='',fileno($ftp),1) = 1;
 select($rout=$rin, undef, undef, undef);

 $ftp-&gt;response();
 $non_pasv-&gt;response();

 return undef
	unless $ftp-&gt;ok() &amp;&amp; $non_pasv-&gt;ok();

 return $1
	if $ftp-&gt;message =~ /unique file name:\s*(\S*)\s*\)/;

 return $1
	if $non_pasv-&gt;message =~ /unique file name:\s*(\S*)\s*\)/;

 return 1;
}

sub cmd { shift-&gt;command(@_)-&gt;response() }

########################################
#
# RFC959 commands
#

sub _ABOR { shift-&gt;command("ABOR")-&gt;response()	 == CMD_OK }
sub _CDUP { shift-&gt;command("CDUP")-&gt;response()	 == CMD_OK }
sub _NOOP { shift-&gt;command("NOOP")-&gt;response()	 == CMD_OK }
sub _PASV { shift-&gt;command("PASV")-&gt;response()	 == CMD_OK }
sub _QUIT { shift-&gt;command("QUIT")-&gt;response()	 == CMD_OK }
sub _DELE { shift-&gt;command("DELE",@_)-&gt;response() == CMD_OK }
sub _CWD  { shift-&gt;command("CWD", @_)-&gt;response() == CMD_OK }
sub _PORT { shift-&gt;command("PORT",@_)-&gt;response() == CMD_OK }
sub _RMD  { shift-&gt;command("RMD", @_)-&gt;response() == CMD_OK }
sub _MKD  { shift-&gt;command("MKD", @_)-&gt;response() == CMD_OK }
sub _PWD  { shift-&gt;command("PWD", @_)-&gt;response() == CMD_OK }
sub _TYPE { shift-&gt;command("TYPE",@_)-&gt;response() == CMD_OK }
sub _RNTO { shift-&gt;command("RNTO",@_)-&gt;response() == CMD_OK }
sub _RESP { shift-&gt;command("RESP",@_)-&gt;response() == CMD_OK }
sub _MDTM { shift-&gt;command("MDTM",@_)-&gt;response() == CMD_OK }
sub _SIZE { shift-&gt;command("SIZE",@_)-&gt;response() == CMD_OK }
sub _HELP { shift-&gt;command("HELP",@_)-&gt;response() == CMD_OK }
sub _STAT { shift-&gt;command("STAT",@_)-&gt;response() == CMD_OK }
sub _APPE { shift-&gt;command("APPE",@_)-&gt;response() == CMD_INFO }
sub _LIST { shift-&gt;command("LIST",@_)-&gt;response() == CMD_INFO }
sub _NLST { shift-&gt;command("NLST",@_)-&gt;response() == CMD_INFO }
sub _RETR { shift-&gt;command("RETR",@_)-&gt;response() == CMD_INFO }
sub _STOR { shift-&gt;command("STOR",@_)-&gt;response() == CMD_INFO }
sub _STOU { shift-&gt;command("STOU",@_)-&gt;response() == CMD_INFO }
sub _RNFR { shift-&gt;command("RNFR",@_)-&gt;response() == CMD_MORE }
sub _REST { shift-&gt;command("REST",@_)-&gt;response() == CMD_MORE }
sub _USER { shift-&gt;command("user",@_)-&gt;response() } # A certain brain dead firewall :-)
sub _PASS { shift-&gt;command("PASS",@_)-&gt;response() }
sub _ACCT { shift-&gt;command("ACCT",@_)-&gt;response() }
sub _AUTH { shift-&gt;command("AUTH",@_)-&gt;response() }

sub _ALLO { shift-&gt;unsupported(@_) }
sub _SMNT { shift-&gt;unsupported(@_) }
sub _MODE { shift-&gt;unsupported(@_) }
sub _SYST { shift-&gt;unsupported(@_) }
sub _STRU { shift-&gt;unsupported(@_) }
sub _REIN { shift-&gt;unsupported(@_) }

1;

__END__

=head1 NAME

Net::FTP - FTP Client class

=head1 SYNOPSIS

    use Net::FTP;

    $ftp = Net::FTP-&gt;new("some.host.name", Debug =&gt; 0);
    $ftp-&gt;login("anonymous",'-anonymous@');
    $ftp-&gt;cwd("/pub");
    $ftp-&gt;get("that.file");
    $ftp-&gt;quit;

=head1 DESCRIPTION

C&lt;Net::FTP&gt; is a class implementing a simple FTP client in Perl as
described in RFC959.  It provides wrappers for a subset of the RFC959
commands.

=head1 OVERVIEW

FTP stands for File Transfer Protocol.  It is a way of transferring
files between networked machines.  The protocol defines a client
(whose commands are provided by this module) and a server (not
implemented in this module).  Communication is always initiated by the
client, and the server responds with a message and a status code (and
sometimes with data).

The FTP protocol allows files to be sent to or fetched from the
server.  Each transfer involves a B&lt;local file&gt; (on the client) and a
B&lt;remote file&gt; (on the server).  In this module, the same file name
will be used for both local and remote if only one is specified.  This
means that transferring remote file C&lt;/path/to/file&gt; will try to put
that file in C&lt;/path/to/file&gt; locally, unless you specify a local file
name.

The protocol also defines several standard B&lt;translations&gt; which the
file can undergo during transfer.  These are ASCII, EBCDIC, binary,
and byte.  ASCII is the default type, and indicates that the sender of
files will translate the ends of lines to a standard representation
which the receiver will then translate back into their local
representation.  EBCDIC indicates the file being transferred is in
EBCDIC format.  Binary (also known as image) format sends the data as
a contiguous bit stream.  Byte format transfers the data as bytes, the
values of which remain the same regardless of differences in byte size
between the two machines (in theory - in practice you should only use
this if you really know what you're doing).

=head1 CONSTRUCTOR

=over 4

=item new (HOST [,OPTIONS])

This is the constructor for a new Net::FTP object. C&lt;HOST&gt; is the
name of the remote host to which an FTP connection is required.

C&lt;OPTIONS&gt; are passed in a hash like fashion, using key and value pairs.
Possible options are:

B&lt;Firewall&gt; - The name of a machine which acts as an FTP firewall. This can be
overridden by an environment variable C&lt;FTP_FIREWALL&gt;. If specified, and the
given host cannot be directly connected to, then the
connection is made to the firewall machine and the string C&lt;@hostname&gt; is
appended to the login identifier. This kind of setup is also refered to
as an ftp proxy.

B&lt;FirewallType&gt; - The type of firewall running on the machine indicated by
B&lt;Firewall&gt;. This can be overridden by an environment variable
C&lt;FTP_FIREWALL_TYPE&gt;. For a list of permissible types, see the description of
ftp_firewall_type in L&lt;Net::Config&gt;.

B&lt;BlockSize&gt; - This is the block size that Net::FTP will use when doing
transfers. (defaults to 10240)

B&lt;Port&gt; - The port number to connect to on the remote machine for the
FTP connection

B&lt;Timeout&gt; - Set a timeout value (defaults to 120)

B&lt;Debug&gt; - debug level (see the debug method in L&lt;Net::Cmd&gt;)

B&lt;Passive&gt; - If set to a non-zero value then all data transfers will be done
using passive mode. This is not usually required except for some I&lt;dumb&gt;
servers, and some firewall configurations. This can also be set by the
environment variable C&lt;FTP_PASSIVE&gt;.

B&lt;Hash&gt; - If given a reference to a file handle (e.g., C&lt;\*STDERR&gt;),
print hash marks (#) on that filehandle every 1024 bytes.  This
simply invokes the C&lt;hash()&gt; method for you, so that hash marks
are displayed for all transfers.  You can, of course, call C&lt;hash()&gt;
explicitly whenever you'd like.

If the constructor fails undef will be returned and an error message will
be in $@

=back

=head1 METHODS

Unless otherwise stated all methods return either a I&lt;true&gt; or I&lt;false&gt;
value, with I&lt;true&gt; meaning that the operation was a success. When a method
states that it returns a value, failure will be returned as I&lt;undef&gt; or an
empty list.

=over 4

=item login ([LOGIN [,PASSWORD [, ACCOUNT] ] ])

Log into the remote FTP server with the given login information. If
no arguments are given then the C&lt;Net::FTP&gt; uses the C&lt;Net::Netrc&gt;
package to lookup the login information for the connected host.
If no information is found then a login of I&lt;anonymous&gt; is used.
If no password is given and the login is I&lt;anonymous&gt; then I&lt;anonymous@&gt;
will be used for password.

If the connection is via a firewall then the C&lt;authorize&gt; method will
be called with no arguments.

=item authorize ( [AUTH [, RESP]])

This is a protocol used by some firewall ftp proxies. It is used
to authorise the user to send data out.  If both arguments are not specified
then C&lt;authorize&gt; uses C&lt;Net::Netrc&gt; to do a lookup.

=item site (ARGS)

Send a SITE command to the remote server and wait for a response.

Returns most significant digit of the response code.

=item type (TYPE [, ARGS])

This method will send the TYPE command to the remote FTP server
to change the type of data transfer. The return value is the previous
value.

=item ascii ([ARGS]) binary([ARGS]) ebcdic([ARGS]) byte([ARGS])

Synonyms for C&lt;type&gt; with the first arguments set correctly

B&lt;NOTE&gt; ebcdic and byte are not fully supported.

=item rename ( OLDNAME, NEWNAME )

Rename a file on the remote FTP server from C&lt;OLDNAME&gt; to C&lt;NEWNAME&gt;. This
is done by sending the RNFR and RNTO commands.

=item delete ( FILENAME )

Send a request to the server to delete C&lt;FILENAME&gt;.

=item cwd ( [ DIR ] )

Attempt to change directory to the directory given in C&lt;$dir&gt;.  If
C&lt;$dir&gt; is C&lt;".."&gt;, the FTP C&lt;CDUP&gt; command is used to attempt to
move up one directory. If no directory is given then an attempt is made
to change the directory to the root directory.

=item cdup ()

Change directory to the parent of the current directory.

=item pwd ()

Returns the full pathname of the current directory.

=item restart ( WHERE )

Set the byte offset at which to begin the next data transfer. Net::FTP simply
records this value and uses it when during the next data transfer. For this
reason this method will not return an error, but setting it may cause
a subsequent data transfer to fail.

=item rmdir ( DIR )

Remove the directory with the name C&lt;DIR&gt;.

=item mkdir ( DIR [, RECURSE ])

Create a new directory with the name C&lt;DIR&gt;. If C&lt;RECURSE&gt; is I&lt;true&gt; then
C&lt;mkdir&gt; will attempt to create all the directories in the given path.

Returns the full pathname to the new directory.

=item ls ( [ DIR ] )

Get a directory listing of C&lt;DIR&gt;, or the current directory.

In an array context, returns a list of lines returned from the server. In
a scalar context, returns a reference to a list.

=item dir ( [ DIR ] )

Get a directory listing of C&lt;DIR&gt;, or the current directory in long format.

In an array context, returns a list of lines returned from the server. In
a scalar context, returns a reference to a list.

=item get ( REMOTE_FILE [, LOCAL_FILE [, WHERE]] )

Get C&lt;REMOTE_FILE&gt; from the server and store locally. C&lt;LOCAL_FILE&gt; may be
a filename or a filehandle. If not specified, the file will be stored in
the current directory with the same leafname as the remote file.

If C&lt;WHERE&gt; is given then the first C&lt;WHERE&gt; bytes of the file will
not be transfered, and the remaining bytes will be appended to
the local file if it already exists.

Returns C&lt;LOCAL_FILE&gt;, or the generated local file name if C&lt;LOCAL_FILE&gt;
is not given. If an error was encountered undef is returned.

=item put ( LOCAL_FILE [, REMOTE_FILE ] )

Put a file on the remote server. C&lt;LOCAL_FILE&gt; may be a name or a filehandle.
If C&lt;LOCAL_FILE&gt; is a filehandle then C&lt;REMOTE_FILE&gt; must be specified. If
C&lt;REMOTE_FILE&gt; is not specified then the file will be stored in the current
directory with the same leafname as C&lt;LOCAL_FILE&gt;.

Returns C&lt;REMOTE_FILE&gt;, or the generated remote filename if C&lt;REMOTE_FILE&gt;
is not given.

B&lt;NOTE&gt;: If for some reason the transfer does not complete and an error is
returned then the contents that had been transfered will not be remove
automatically.

=item put_unique ( LOCAL_FILE [, REMOTE_FILE ] )

Same as put but uses the C&lt;STOU&gt; command.

Returns the name of the file on the server.

=item append ( LOCAL_FILE [, REMOTE_FILE ] )

Same as put but appends to the file on the remote server.

Returns C&lt;REMOTE_FILE&gt;, or the generated remote filename if C&lt;REMOTE_FILE&gt;
is not given.

=item unique_name ()

Returns the name of the last file stored on the server using the
C&lt;STOU&gt; command.

=item mdtm ( FILE )

Returns the I&lt;modification time&gt; of the given file

=item size ( FILE )

Returns the size in bytes for the given file as stored on the remote server.

B&lt;NOTE&gt;: The size reported is the size of the stored file on the remote server.
If the file is subsequently transfered from the server in ASCII mode
and the remote server and local machine have different ideas about
"End Of Line" then the size of file on the local machine after transfer
may be different.

=item supported ( CMD )

Returns TRUE if the remote server supports the given command.

=item hash ( [FILEHANDLE_GLOB_REF],[ BYTES_PER_HASH_MARK] )

Called without parameters, or with the first argument false, hash marks
are suppressed.  If the first argument is true but not a reference to a 
file handle glob, then \*STDERR is used.  The second argument is the number
of bytes per hash mark printed, and defaults to 1024.  In all cases the
return value is a reference to an array of two:  the filehandle glob reference
and the bytes per hash mark.

=back

The following methods can return different results depending on
how they are called. If the user explicitly calls either
of the C&lt;pasv&gt; or C&lt;port&gt; methods then these methods will
return a I&lt;true&gt; or I&lt;false&gt; value. If the user does not
call either of these methods then the result will be a
reference to a C&lt;Net::FTP::dataconn&gt; based object.

=over 4

=item nlst ( [ DIR ] )

Send an C&lt;NLST&gt; command to the server, with an optional parameter.

=item list ( [ DIR ] )

Same as C&lt;nlst&gt; but using the C&lt;LIST&gt; command

=item retr ( FILE )

Begin the retrieval of a file called C&lt;FILE&gt; from the remote server.

=item stor ( FILE )

Tell the server that you wish to store a file. C&lt;FILE&gt; is the
name of the new file that should be created.

=item stou ( FILE )

Same as C&lt;stor&gt; but using the C&lt;STOU&gt; command. The name of the unique
file which was created on the server will be available via the C&lt;unique_name&gt;
method after the data connection has been closed.

=item appe ( FILE )

Tell the server that we want to append some data to the end of a file
called C&lt;FILE&gt;. If this file does not exist then create it.

=back

If for some reason you want to have complete control over the data connection,
this includes generating it and calling the C&lt;response&gt; method when required,
then the user can use these methods to do so.

However calling these methods only affects the use of the methods above that
can return a data connection. They have no effect on methods C&lt;get&gt;, C&lt;put&gt;,
C&lt;put_unique&gt; and those that do not require data connections.

=over 4

=item port ( [ PORT ] )

Send a C&lt;PORT&gt; command to the server. If C&lt;PORT&gt; is specified then it is sent
to the server. If not, then a listen socket is created and the correct information
sent to the server.

=item pasv ()

Tell the server to go into passive mode. Returns the text that represents the
port on which the server is listening, this text is in a suitable form to
sent to another ftp server using the C&lt;port&gt; method.

=back

The following methods can be used to transfer files between two remote
servers, providing that these two servers can connect directly to each other.

=over 4

=item pasv_xfer ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )

This method will do a file transfer between two remote ftp servers. If
C&lt;DEST_FILE&gt; is omitted then the leaf name of C&lt;SRC_FILE&gt; will be used.

=item pasv_xfer_unique ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )

Like C&lt;pasv_xfer&gt; but the file is stored on the remote server using
the STOU command.

=item pasv_wait ( NON_PASV_SERVER )

This method can be used to wait for a transfer to complete between a passive
server and a non-passive server. The method should be called on the passive
server with the C&lt;Net::FTP&gt; object for the non-passive server passed as an
argument.

=item abort ()

Abort the current data transfer.

=item quit ()

Send the QUIT command to the remote FTP server and close the socket connection.

=back

=head2 Methods for the adventurous

C&lt;Net::FTP&gt; inherits from C&lt;Net::Cmd&gt; so methods defined in C&lt;Net::Cmd&gt; may
be used to send commands to the remote FTP server.

=over 4

=item quot (CMD [,ARGS])

Send a command, that Net::FTP does not directly support, to the remote
server and wait for a response.

Returns most significant digit of the response code.

B&lt;WARNING&gt; This call should only be used on commands that do not require
data connections. Misuse of this method can hang the connection.

=back

=head1 THE dataconn CLASS

Some of the methods defined in C&lt;Net::FTP&gt; return an object which will
be derived from this class.The dataconn class itself is derived from
the C&lt;IO::Socket::INET&gt; class, so any normal IO operations can be performed.
However the following methods are defined in the dataconn class and IO should
be performed using these.

=over 4

=item read ( BUFFER, SIZE [, TIMEOUT ] )

Read C&lt;SIZE&gt; bytes of data from the server and place it into C&lt;BUFFER&gt;, also
performing any &lt;CRLF&gt; translation necessary. C&lt;TIMEOUT&gt; is optional, if not
given, the timeout value from the command connection will be used.

Returns the number of bytes read before any &lt;CRLF&gt; translation.

=item write ( BUFFER, SIZE [, TIMEOUT ] )

Write C&lt;SIZE&gt; bytes of data from C&lt;BUFFER&gt; to the server, also
performing any &lt;CRLF&gt; translation necessary. C&lt;TIMEOUT&gt; is optional, if not
given, the timeout value from the command connection will be used.

Returns the number of bytes written before any &lt;CRLF&gt; translation.

=item bytes_read ()

Returns the number of bytes read so far.

=item abort ()

Abort the current data transfer.

=item close ()

Close the data connection and get a response from the FTP server. Returns
I&lt;true&gt; if the connection was closed successfully and the first digit of
the response from the server was a '2'.

=back

=head1 UNIMPLEMENTED

The following RFC959 commands have not been implemented:

=over 4

=item B&lt;ALLO&gt;

Allocates storage for the file to be transferred.

=item B&lt;SMNT&gt;

Mount a different file system structure without changing login or
accounting information.

=item B&lt;HELP&gt;

Ask the server for "helpful information" (that's what the RFC says) on
the commands it accepts.

=item B&lt;MODE&gt;

Specifies transfer mode (stream, block or compressed) for file to be
transferred.

=item B&lt;SYST&gt;

Request remote server system identification.

=item B&lt;STAT&gt;

Request remote server status.

=item B&lt;STRU&gt;

Specifies file structure for file to be transferred.

=item B&lt;REIN&gt;

Reinitialize the connection, flushing all I/O and account information.

=back

=head1 REPORTING BUGS

When reporting bugs/problems please include as much information as possible.
It may be difficult for me to reproduce the problem as almost every setup
is different.

A small script which yields the problem will probably be of help. It would
also be useful if this script was run with the extra options C&lt;Debug =&gt; 1&gt;
passed to the constructor, and the output sent with the bug report. If you
cannot include a small script then please include a Debug trace from a
run of your program which does yield the problem.

=head1 AUTHOR

Graham Barr &lt;gbarr@pobox.com&gt;

=head1 SEE ALSO

L&lt;Net::Netrc&gt;
L&lt;Net::Cmd&gt;

ftp(1), ftpd(8), RFC 959
http://www.cis.ohio-state.edu/htbin/rfc/rfc959.html

=head1 USE EXAMPLES

For an example of the use of Net::FTP see

=over 4

=item http://www.csh.rit.edu/~adam/Progs/autoftp-2.0.tar.gz

C&lt;autoftp&gt; is a program that can retrieve, send, or list files via
the FTP protocol in a non-interactive manner.

=back

=head1 CREDITS

Henry Gabryjelski &lt;henryg@WPI.EDU&gt; - for the suggestion of creating directories
recursively.

Nathan Torkington &lt;gnat@frii.com&gt; - for some input on the documentation.

Roderick Schertler &lt;roderick@gate.net&gt; - for various inputs

=head1 COPYRIGHT

Copyright (c) 1995-1998 Graham Barr. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=for html &lt;hr&gt;

I&lt;$Id: //depot/libnet/Net/FTP.pm#68 $&gt;

=cut
</pre></body></html>