home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Editores / Perl5 / perl / lib / site / Net / FTP.pm < prev    next >
Encoding:
Perl POD Document  |  1997-08-10  |  34.2 KB  |  1,539 lines

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