#!/usr/bin/perl -w

my $OutDir = shift @ARGV || die "Usage: SMDfetchMeta.pl OutDirectory\n";
my $BaseURL = "ftp://genome-ftp.stanford.edu/pub/smd/publications";
my $LinksCMD = "links -source";  # not simple to use ncftpget on directories

open(PUBS, "$LinksCMD $BaseURL |") || die "Cannot open pipe for $LinksCMD $BaseURL";
while(<PUBS>) {
    if ($_ =~ m!<a href="([0-9]+)/">!) {
	my $pub = $1;
	my $cmd = "$LinksCMD $BaseURL/$pub/publication_$pub.meta > $OutDir/publication_$pub.meta";
	system($cmd)==0 || die "Command failed: $cmd";
    }
}
close(PUBS) || die "Cannot close pipe for $BaseURL";
