#!/usr/bin/perl

use Net::FTP::Recursive;
use FileHandle;

####################################################################
# 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
$filename = shift;

$fh = new FileHandle;
$fh->open(">$filename");

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

$ftp->login($username, $passwd) or die "Could not log in!";
$ftp->binary();

$ftp->cwd($remote_path);

$ftp->rdir( Filehandle => $fh );

$fh->close;

$ftp->quit;

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

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