From ad81e54381b6298502e57c681499394cd4e0756e Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Sat, 28 Dec 2013 13:22:19 -0800 Subject: [PATCH] add working geo_downloader --- geo_downloader | 53 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/geo_downloader b/geo_downloader index 541d319..a1c3953 100755 --- a/geo_downloader +++ b/geo_downloader @@ -52,6 +52,8 @@ geo_downloader GSE20400 use vars qw($DEBUG); use Net::FTP; +use Cwd; +use Data::Printer; my %options = (debug => 0, help => 0, @@ -91,18 +93,55 @@ print STDERR "logged in\n" if $DEBUG; $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); -- 2.39.2