home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl_ste.zip / auto / Net / FTP / login.al < prev    next >
Text File  |  1997-11-28  |  1KB  |  61 lines

  1. # NOTE: Derived from ./blib/lib/Net/FTP.pm.  Changes made here will be lost.
  2. package Net::FTP;
  3.  
  4. sub login
  5. {
  6.  my($ftp,$user,$pass,$acct) = @_;
  7.  my($ok,$ruser);
  8.  
  9.  unless (defined $user)
  10.   {
  11.    require Net::Netrc;
  12.  
  13.    my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'});
  14.  
  15.    ($user,$pass,$acct) = $rc->lpa()
  16.     if ($rc);
  17.   }
  18.  
  19.  $user ||= "anonymous";
  20.  $ruser = $user;
  21.  
  22.  if(defined ${*$ftp}{'net_ftp_firewall'})
  23.   {
  24.    $user .= "@" . ${*$ftp}{'net_ftp_host'};
  25.   }
  26.  
  27.  $ok = $ftp->_USER($user);
  28.  
  29.  # Some dumb firewalls don't prefix the connection messages
  30.  $ok = $ftp->response()
  31.     if($ok == CMD_OK && $ftp->code == 220 && $user =~ /\@/);
  32.  
  33.  if ($ok == CMD_MORE)
  34.   {
  35.    unless(defined $pass)
  36.     {
  37.      require Net::Netrc;
  38.  
  39.      my $rc = Net::Netrc->lookup(${*$ftp}{'net_ftp_host'}, $ruser);
  40.  
  41.      ($ruser,$pass,$acct) = $rc->lpa()
  42.     if ($rc);
  43.  
  44.      $pass = "-" . (getpwuid($>))[0] . "@" 
  45.         if (!defined $pass && (!defined($ruser) || $ruser =~ /^anonymous/o));
  46.     }
  47.  
  48.    $ok = $ftp->_PASS($pass || "");
  49.   }
  50.  
  51.  $ok = $ftp->_ACCT($acct || "")
  52.     if ($ok == CMD_MORE);
  53.  
  54.  $ftp->authorize()
  55.     if($ok == CMD_OK && defined ${*$ftp}{'net_ftp_firewall'});
  56.  
  57.  $ok == CMD_OK;
  58. }
  59.  
  60. 1;
  61.