summaryrefslogtreecommitdiffstats
path: root/perl-install/ftp.pm
blob: e6c27e68c43bcd0ceb755720efb6e55015ba0d55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package ftp;

use Net::FTP;

use install_any;
use log;

# non-rentrant!!

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
           (?: :([^@]*))?       # password
       @)?
       ([^/]*)                	# host
       /?(.*)			# prefix
      |x;
}
unless ($ENV{LOGIN}) {
    $ENV{LOGIN} = 'anonymous';
    $ENV{PASSWORD} = 'mdkinst@test';
}

my $host = $ENV{HOST};
if ($host !~ /^[.\d]+$/) {
    $host = join ".", unpack "C4", (gethostbyname $host)[4];
    print ">>>>> $host <<<<<<\n";
}

my $ftp = Net::FTP->new($host, %options) or die;
$ftp->login($ENV{LOGIN}, $ENV{PASSWORD}) or die;
$ftp->binary;

my $retr;

1;


sub getFile($) {
    $retr->close if $retr;
    $retr = $ftp->retr($ENV{PREFIX} . "/" . install_any::relGetFile($_[0]));
}