use vars qw($DEBUG);
use Net::FTP;
+use Cwd;
+use Data::Printer;
my %options = (debug => 0,
help => 0,
$ftp->binary();
print STDERR "binary\n" if $DEBUG;
-
+use Data::Printer;
for my $geo_acc (@ARGV) {
my $geo_directory = geo_directory($geo_acc);
- $ftp->cwd($geo_directory);
- print STDERR "changed to $geo_directory\n" if $DEBUG;
- print STDERR "(really) changed to ".$ftp->pwd()."\n" if $DEBUG;
- my @files = $ftp->ls();
- print map {$_."\n"} @files;
- print STDERR "transferred listing\n" if $DEBUG;
+ my $listing = recursive_file_listing($ftp,$geo_directory);
+ p($listing) if $DEBUG;
+ my $orig_dir = getcwd;
+ mkdir($geo_acc) unless -d $geo_acc;
+ chdir($geo_acc);
+ for my $dir (qw(matrix miniml suppl)) {
+ # we want all of the raw files, the xml file, and the matrix file
+ if (exists $listing->{$dir} and ref($listing->{$dir})) {
+ for my $file (keys %{$listing->{$dir}}) {
+ next if ref($listing->{$dir}{$file});
+ $ftp->get($listing->{$dir}{$file});
+ }
+ }
+ }
+ chdir($orig_dir);
}
+
+sub recursive_file_listing {
+ my ($ftp,$dir) = @_;
+ my $listing;
+ my $orig_dir = $ftp->pwd();
+ eval {
+ $ftp->cwd($dir) or die "Not a directory $dir";
+ $listing = {};
+ my @files = $ftp->ls();
+ p @files if $DEBUG;
+ for my $file (@files) {
+ print STDERR "file: $file\n";
+ my $subdirs = recursive_file_listing($ftp,$file);
+ print STDERR "subdirs is :";
+ print STDERR p($subdirs);
+ if (defined $subdirs) {
+ $listing->{$file} = $subdirs;
+ } else {
+ $listing->{$file} = $orig_dir.'/'.$dir.'/'.$file;
+ }
+ }
+ };
+ $ftp->cwd($orig_dir);
+ return $listing;
+}
+
+
+
sub geo_directory {
my $geo_acc = shift;
$geo_acc = uc($geo_acc);