I am somewhat a Perl Noob, but I've done some programming with my animal books at my side. This issue, however doesn't make sense to me. I am grabbing data via FTP corresponding to data I've already downloaded (this is a pre-processing front end to some other fortran code). However, in the part indicated below (the second FTP execution), I get a login failure, even both ftp sites allow anonymous FTP.
Any thoughts or suggestions on how I might run this down would be much appreciated.
Sincerely,
Todd
Code pasted below
----------------------------
#!/usr/bin/perl
use Net::FTP;
$ftp_username = 'anonymous';
$ftp_passwd = 'BLOCKED - this would normally be my email'
my ($tsec, $tmin, $thour, $mday, $mmon, $yyear, $wday, $yday, $isdst) = localtime time;
$yyear += 1900;
#initialize arrays with strings
@month_str = ('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
@day_str = ('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31');
# set local AMSU data directory
$AMSUdir = 'data/2005';
chdir $AMSUdir or die "cannot change dir to $AMSU_dir: $!";
@AMSUfiles = glob "*.eos";
# loop through each file to grab relevant ancillary data
foreach $AMSU (@AMSUfiles) {
# do not grab more data if this swath is in same day as last swath
if ($AMSU ne $hold_name) {
# capture the year and the doy
if ($AMSU =~ /\w+(\d{4})\.(\d +)\w\d+\w\d+\w\ d+\w+\.eos/) {
$year = $1*1;
$doy = $2;
# convert dayofyear to date
if ($year % 4 eq 0) {
@days_by_month = (31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366);
} else {
@days_by_month = (31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365);
}
$month = 1;
$dd = $2*1;
foreach $dm (@days_by_month ) {
if ($2 <= $dm) {
$day = $dd;
} else {
$dd = $2 - $dm;
$month++;
}
}
$mo_string = $month_str[$month-1];
$day_string = $day_str[$day-1];
# get the SSMI data
$ssmi_dir = "/ssmi/f15/bmaps_v06/y$year/m$mo_string/";
$ssmi_filename = "f15_$year$mo_s tring$day_strin gv6.gz";
$ssmi_site = 'ftp.ssmi.com';
$ftp_obj = Net::FTP -> new ($ssmi_site, Timeout => 20) or
die "Cannot access $ssmi_site via FTP\n";
$ftp_obj -> login($ftp_user name, $ftp_passwd) or
die "Invalid user name and/or password SSMI\n";
$ftp_obj -> binary;
$ftp_obj -> cwd ("$ssmi_dir" ) or
die "Cannot access directory $ssmi_dir\n";
$ftp_obj -> get("$ssmi_file name");
$ftp_obj -> quit;
# get the SST data
$sst_dir = "/sst/daily/tmi_amsre/";
$sst_filename = "tmi_amsre.fusi on.$year.$doy.v 02.gz";
$sst_site = 'ftp.discover-earth.org';
$ftp_obj -> new ($sst_site, Timeout=>20) or
die "Cannot access $sst_site via FTP\n";
# this next line throws out an invalid login error
$ftp_obj -> login($ftp_user name, $ftp_passwd) or
die "Invalid user name and/or password SST\n";
$ftp_obj -> binary;
$ftp_obj -> cwd ("$sst_dir") or
die "Cannot access directory $sst_dir\n";
$ftp_obj -> get("$sst_filen ame");
$ftp_obj -> quit;
}
}
# set this string for next time through
$hold_name = $AMSU;
# write out the relevant data
print "$year $doy $AMSU $ssmi_filename $sst_filename\n ";
}
# make a new data for all data
$data_dir = "data_$thour$tm in_$yday_$yyear ";
mkdir $data_dir, 0777;
# move all the data
foreach my $file (glob "*.eos") {
my $newfile = "$data_dir/$file";
rename $file, $newfile;
}
foreach my $file (glob "*.gz") {
my $newfile = "$data_dir/$file";
rename $file, $newfile;
}
Any thoughts or suggestions on how I might run this down would be much appreciated.
Sincerely,
Todd
Code pasted below
----------------------------
#!/usr/bin/perl
use Net::FTP;
$ftp_username = 'anonymous';
$ftp_passwd = 'BLOCKED - this would normally be my email'
my ($tsec, $tmin, $thour, $mday, $mmon, $yyear, $wday, $yday, $isdst) = localtime time;
$yyear += 1900;
#initialize arrays with strings
@month_str = ('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
@day_str = ('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31');
# set local AMSU data directory
$AMSUdir = 'data/2005';
chdir $AMSUdir or die "cannot change dir to $AMSU_dir: $!";
@AMSUfiles = glob "*.eos";
# loop through each file to grab relevant ancillary data
foreach $AMSU (@AMSUfiles) {
# do not grab more data if this swath is in same day as last swath
if ($AMSU ne $hold_name) {
# capture the year and the doy
if ($AMSU =~ /\w+(\d{4})\.(\d +)\w\d+\w\d+\w\ d+\w+\.eos/) {
$year = $1*1;
$doy = $2;
# convert dayofyear to date
if ($year % 4 eq 0) {
@days_by_month = (31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366);
} else {
@days_by_month = (31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365);
}
$month = 1;
$dd = $2*1;
foreach $dm (@days_by_month ) {
if ($2 <= $dm) {
$day = $dd;
} else {
$dd = $2 - $dm;
$month++;
}
}
$mo_string = $month_str[$month-1];
$day_string = $day_str[$day-1];
# get the SSMI data
$ssmi_dir = "/ssmi/f15/bmaps_v06/y$year/m$mo_string/";
$ssmi_filename = "f15_$year$mo_s tring$day_strin gv6.gz";
$ssmi_site = 'ftp.ssmi.com';
$ftp_obj = Net::FTP -> new ($ssmi_site, Timeout => 20) or
die "Cannot access $ssmi_site via FTP\n";
$ftp_obj -> login($ftp_user name, $ftp_passwd) or
die "Invalid user name and/or password SSMI\n";
$ftp_obj -> binary;
$ftp_obj -> cwd ("$ssmi_dir" ) or
die "Cannot access directory $ssmi_dir\n";
$ftp_obj -> get("$ssmi_file name");
$ftp_obj -> quit;
# get the SST data
$sst_dir = "/sst/daily/tmi_amsre/";
$sst_filename = "tmi_amsre.fusi on.$year.$doy.v 02.gz";
$sst_site = 'ftp.discover-earth.org';
$ftp_obj -> new ($sst_site, Timeout=>20) or
die "Cannot access $sst_site via FTP\n";
# this next line throws out an invalid login error
$ftp_obj -> login($ftp_user name, $ftp_passwd) or
die "Invalid user name and/or password SST\n";
$ftp_obj -> binary;
$ftp_obj -> cwd ("$sst_dir") or
die "Cannot access directory $sst_dir\n";
$ftp_obj -> get("$sst_filen ame");
$ftp_obj -> quit;
}
}
# set this string for next time through
$hold_name = $AMSU;
# write out the relevant data
print "$year $doy $AMSU $ssmi_filename $sst_filename\n ";
}
# make a new data for all data
$data_dir = "data_$thour$tm in_$yday_$yyear ";
mkdir $data_dir, 0777;
# move all the data
foreach my $file (glob "*.eos") {
my $newfile = "$data_dir/$file";
rename $file, $newfile;
}
foreach my $file (glob "*.gz") {
my $newfile = "$data_dir/$file";
rename $file, $newfile;
}
Comment