summaryrefslogtreecommitdiffstats
path: root/perl-install/ftp.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/ftp.pm')
-rw-r--r--perl-install/ftp.pm82
1 files changed, 26 insertions, 56 deletions
diff --git a/perl-install/ftp.pm b/perl-install/ftp.pm
index 36b99b560..e6c27e68c 100644
--- a/perl-install/ftp.pm
+++ b/perl-install/ftp.pm
@@ -3,16 +3,17 @@ package ftp;
use Net::FTP;
use install_any;
-use network;
use log;
-my %hosts;
+# non-rentrant!!
-1;
-
-sub fromEnv() {
- # using URLPREFIX to find out information if kickstart
- ($ENV{LOGIN}, $ENV{PASSWORD}, $ENV{HOST}, $ENV{PREFIX}) =
+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|
://
(?: ([^:]*) # login
@@ -20,60 +21,29 @@ sub fromEnv() {
@)?
([^/]*) # host
/?(.*) # prefix
- |x unless $ENV{HOST};
-
- @ENV{qw(HOST PREFIX LOGIN PASSWORD)};
+ |x;
}
-
-sub new {
- my ($host, $prefix, $login, $password) = @_;
- my @l = do { if ($hosts{"$host$prefix"}) {
- @{$hosts{"$host$prefix"}};
- } else {
- my %options = (Passive => 1, Timeout => 60, Port => 21);
- $options{Firewall} = $ENV{PROXY} if $ENV{PROXY};
- $options{Port} = $ENV{PROXYPORT} if $ENV{PROXYPORT};
- unless ($login) {
- $login = 'anonymous';
- $password = '-drakx@';
- }
-
- 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$prefix"} = \@l;
- @l;
- }};
- wantarray ? @l : $l[0];
+unless ($ENV{LOGIN}) {
+ $ENV{LOGIN} = 'anonymous';
+ $ENV{PASSWORD} = 'mdkinst@test';
}
-sub getFile {
- my $f = shift;
- my ($ftp, $retr) = new(@_ ? @_ : fromEnv);
- $$retr->close if $$retr;
- $$retr = $ftp->retr(install_any::relGetFile($f)) or rewindGetFile();
- $$retr ||= $ftp->retr(install_any::relGetFile($f));
+my $host = $ENV{HOST};
+if ($host !~ /^[.\d]+$/) {
+ $host = join ".", unpack "C4", (gethostbyname $host)[4];
+ print ">>>>> $host <<<<<<\n";
}
-#-sub closeFiles() {
-#- #- close any existing connections
-#- foreach (values %hosts) {
-#- my $retr = $_->[1] if ref $_;
-#- $$retr->close if $$retr;
-#- undef $$retr;
-#- }
-#-}
+my $ftp = Net::FTP->new($host, %options) or die;
+$ftp->login($ENV{LOGIN}, $ENV{PASSWORD}) or die;
+$ftp->binary;
+
+my $retr;
+
+1;
-sub rewindGetFile() {
- #- close any existing connection.
- foreach (values %hosts) {
- my ($ftp) = @{$_ || []};
- $ftp->close() if $ftp;
- }
- #- make sure to reconnect to server.
- %hosts = ();
+sub getFile($) {
+ $retr->close if $retr;
+ $retr = $ftp->retr($ENV{PREFIX} . "/" . install_any::relGetFile($_[0]));
}