#!/usr/bin/perl
my
$use_windows
;
GetOptions(
'help|?'
=>
sub
{ pod2usage(); },
'windows'
=> \
$use_windows
,
);
pod2usage()
unless
@ARGV
>= 5;
my
$host
=
shift
;
my
$username
=
shift
;
my
$passwd
=
shift
;
my
$remote_path
=
shift
;
my
$local_path
=
shift
;
my
%rget_args
= (
map
{ (
$_
=> 1 ) }
@ARGV
,
(
$use_windows
? (
ParseSub
=> \
&parse_sub
) : () ) );
chdir
$local_path
or
die
"could not change dir to $local_path!"
;
my
$ftp
= Net::FTP::Recursive->new(
$host
,
Debug
=> 1)
or
die
"Could not connect to $host!"
;
$ftp
->login(
$username
,
$passwd
) or
die
"Could not log in!"
;
$ftp
->binary();
$ftp
->cwd(
$remote_path
)
or
die
"could not change to $remote_path on the ftp server!"
;
my
$output
=
$ftp
->rget(
%rget_args
);
$ftp
->quit;
print
"Got \$output of:\n$output\n"
;
exit
;
sub
parse_sub{
my
(
@to_return
) = ();
foreach
my
$line
(
@_
) {
my
(
$file
);
next
unless
my
@fields
=
$line
=~ /^
(\S+)\s+
(\S+)\s+
(<DIR>)?\s*
(\d+)\s+
(.+?)\s*
(?:->\s*(.+))?
$
/x;
@fields
= (
$fields
[2],
undef
,
undef
,
undef
,
$fields
[3],
"$fields[0]$fields[1]"
,
@fields
[4,5] );
my
(
$perms
) = (
$fields
[0]);
next
if
$fields
[6] =~ /^\.{1,2}$/;
if
(
$perms
=~ /<DIR>/){
$file
= Net::FTP::Recursive::File->new(
IsPlainFile
=> 0,
IsDirectory
=> 1,
IsSymlink
=> 0,
OriginalLine
=>
$line
,
Fields
=> [
@fields
]);
}
else
{
$file
= Net::FTP::Recursive::File->new(
IsDirectory
=> 0,
IsPlainFile
=> 1,
IsSymlink
=> 0,
OriginalLine
=>
$line
,
Fields
=> [
@fields
]);
}
push
(
@to_return
,
$file
);
}
return
(
@to_return
);
}