diff options
author | Pascal Rigaux <pixel@mandriva.com> | 1999-11-28 19:14:45 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 1999-11-28 19:14:45 +0000 |
commit | 2ee22881483e84ea8b5ef0a5125631c04d174617 (patch) | |
tree | 049f83e2f8ef8c2ed3630d26b8a9f9c525202709 /perl-install/ftp.pm | |
parent | 68db145d16c5fa22c876b294411cb9417ad3b08e (diff) | |
download | drakx-backup-do-not-use-2ee22881483e84ea8b5ef0a5125631c04d174617.tar drakx-backup-do-not-use-2ee22881483e84ea8b5ef0a5125631c04d174617.tar.gz drakx-backup-do-not-use-2ee22881483e84ea8b5ef0a5125631c04d174617.tar.bz2 drakx-backup-do-not-use-2ee22881483e84ea8b5ef0a5125631c04d174617.tar.xz drakx-backup-do-not-use-2ee22881483e84ea8b5ef0a5125631c04d174617.zip |
no_comment
Diffstat (limited to 'perl-install/ftp.pm')
-rw-r--r-- | perl-install/ftp.pm | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/perl-install/ftp.pm b/perl-install/ftp.pm index 6c498f2af..bfabc5abf 100644 --- a/perl-install/ftp.pm +++ b/perl-install/ftp.pm @@ -6,45 +6,53 @@ use install_any; use network; use log; -# non-rentrant!! - -my $retr; +my %hosts; 1; - -sub new { - my %options = (Passive => 1); - $options{Firewall} = $ENV{PROXY} if $ENV{PROXY}; - $options{Port} = $ENV{PROXYPORT} if $ENV{PROXYPORT}; - my @l; - unless ($ENV{HOST}) { - # must be in kickstart, using URLPREFIX to find out information - ($ENV{LOGIN}, $ENV{PASSWORD}, $ENV{HOST}, $ENV{PREFIX}) = @l = - $ENV{URLPREFIX} =~ m| +sub fromEnv() { + # using URLPREFIX to find out information if kickstart + ($ENV{LOGIN}, $ENV{PASSWORD}, $ENV{HOST}, $ENV{PREFIX}) = + $ENV{URLPREFIX} =~ m| :// (?: ([^:]*) # login (?: :([^@]*))? # password @)? ([^/]*) # host /?(.*) # prefix - |x; - } - unless ($ENV{LOGIN}) { - $ENV{LOGIN} = 'anonymous'; - $ENV{PASSWORD} = 'mdkinst@test'; - } - - my $ftp = Net::FTP->new(network::resolv($ENV{HOST}), %options) or die ''; - $ftp->login($ENV{LOGIN}, $ENV{PASSWORD}) or die ''; - $ftp->binary; - - $ftp; + |x unless $ENV{HOST}; + + @ENV{qw(HOST PREFIX LOGIN PASSWORD)}; } +sub new { + my ($host, $prefix, $login, $password) = @_; + my @l = do { if ($hosts{$host}) { + @{$hosts{$host}}; + } else { + my %options = (Passive => 1); + $options{Firewall} = $ENV{PROXY} if $ENV{PROXY}; + $options{Port} = $ENV{PROXYPORT} if $ENV{PROXYPORT}; + unless ($login) { + $login = 'anonymous'; + $password = 'DrakX@vivelinuxabaszindozs'; + } + + my $ftp = Net::FTP->new(network::resolv($host), %options) or die ''; + $ftp->login($login, $password) or die ''; + $ftp->binary; + $ftp->cwd($prefix); + + my @l = ($ftp, \ (my $retr = undef)); + $hosts{$host} = \@l; + @l; + }}; + wantarray ? @l : $l[0]; +} sub getFile($) { - $ftp ||= new(); - $retr->close if $retr; - $retr = $ftp->retr($ENV{PREFIX} . "/" . install_any::relGetFile($_[0])); + my $f = shift; + my ($ftp, $retr) = new(@_ ? @_ : fromEnv); + $$retr->close if $$retr; + $$retr = $ftp->retr(install_any::relGetFile($f)); } |