#!/usr/bin/perl

use Net::FTP::Recursive;

####################################################################
# will assume just a few args, as well as validity.
####################################################################

usage() unless @ARGV >= 5;

$host = shift;
$username = shift;
$passwd = shift;
$remote_path = shift; #where to grab from
$local_path = shift; #where to put dir structure on local box.

chdir $local_path or die "could not change dir to $local_path!";

$ftp = Net::FTP::Recursive->new($host, Debug => 1);

$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!";

$output = $ftp->rget( map{($_, 1)} @ARGV);

$ftp->quit;

print "Got \$output of:\n$output\n";

sub usage {
  my($name) = $0;
  $name =~ s#.*/##;

  print STDERR "Usage: $name <host> <username> <passwd> <remote_path> <local_path>\n";
  exit;
}