I wrote a script to download some data from FTP by a subroutine. I tell the program to download the data that belong to my stations which are listed in @station_list array with capital letters. The corresponding data are located at separate pages with the name of the each station in small letters, e.g. ftp://$ftp_srv/$ftp_dir/aaaa is the page for aaaa station and ftp://$ftp_srv/$ftp_dir/bbbb is the page for bbbb station. So, I make a loop for downloading and converting the capital letters to small ones. But it just work for the first station. I don’t know what shall I do to fix it. Thank you for any help.
The following code is the mentioned loop:
foreach $station (@station_list) {
$litte_station = "\L$station\E";
unless ($ftp->cwd($litte_station)) {
$ftp->quit;
print2("Can't cd to $station $!\n");
return (0);
}
$filename = "\L${station}\E${doy}\L$sessionchar\E.${yy}o.gz";
print2 ("Get file: ${ftp_srv}\\${ftp_dir}\\${yyyy}\\${doy}\\${filename} ...");
unless ($ftp->get($filename, $ftp_savepath.$filename)) {
print2(" NOT AVAILABLE\n");
} else {
print2 (" Successful \n");
}
}
In response to your comment on my first answer, I now better understand what you were asking. At the end of your
foreachloop, call$ftp->cdup:That will return you to the parent directory.