Assistance sought. Below i have a programme which copies files by ftp. The programme works. Here's what it does .1 in the foreach $model (@models) loop it goes thru" one of three models. In model1 it copies from one directory to the local directory ="/home/Mumba/ARCHIVE/model/date (date is today's date eg 20081105) In model2 it has to copy from two directories to two local directories ="/home/Mumba/ARCHIVE/model/date and "/home/Mumba/ARCHIVE/model/date+1 In model3 it has to copy from 4 remote directories. Currently it is putting all files in the same local directory for model1 and for model2, thus replacing what was earlier copied. How do I define more local directories so that they can be changed in the "foreach $rdir (@remotedirs)" loop? Assistance will be appreciated. Zilore
$remote_basedir="/home/synergie"; $datadir="/data/grib"; $local_basedir="/home/Mumba/ARCHIVE"; @models=("arpege", "ukmo", "ecmf"); $dat=`date +%Y%m%d`; chomp $dat; # this is a guess so that we don't have to manually edit the script # and input the cycle each time $hr=`date +%H`; chomp $hr; if ( $hr > 15 ) { $cycle="12"; } else { $cycle="00"; } # connect to the remote host # print "Connecting to $Host ...\n"; $ftp = Net::FTP->new($Host, Timeout => 360, Passive=>"true") || &fail ; $ftp->login($User,$Pass) ; $ftp->binary ; $ftp->cwd($datadir); # retrieve data # print "Copying data\n"; foreach $model (@models) { # define local and remote directories before copying files # $localdir="$local_basedir/$model/$dat"; undef @remotedirs; if ( "$model" eq "arpege" ) { $remotedir="${remote_basedir}${datadir}/PS.R2kAF15/${dat}${cycle}0000"; push (@remotedirs, $remotedir); } elsif ( "$model" eq "ukmo" ) { $remotedir="${remote_basedir}${datadir}/UK2.G41/${dat}${cycle}0000"; push (@remotedirs, $remotedir); $remotedir="${remote_basedir}${datadir}/UK2.G37/${dat}${cycle}0000"; push (@remotedirs, $remotedir); } elsif ( "$model" eq "ecmf") { $remotedir="${remote_basedir}${datadir}/PC.G25/${dat}${cycle}0000"; push (@remotedirs, $remotedir); $remotedir="${remote_basedir}${datadir}/PC.G28/${dat}${cycle}0000"; push (@remotedirs, $remotedir); $remotedir="${remote_basedir}${datadir}/PC.G29/${dat}${cycle}0000"; push (@remotedirs, $remotedir); $remotedir="${remote_basedir}${datadir}/PC.G32/${dat}${cycle}0000"; push (@remotedirs, $remotedir); } if (! -d $localdir ) { system("mkdir -p $localdir"); } chdir $localdir; # retrieve files # foreach $rdir (@remotedirs) { print "Retrieving files from $rdir to $localdir\n"; $ftp->cwd($rdir); # perl/ftp doesn't support mget, so we have to get a list # and *then* get the files :( # @files = $ftp->ls; foreach $file (@files) { $ftp->get($file); } } } $ftp->close; print "copying ends\n"; exit 0; #============================================================================ # Subroutines #---------------------------------------------------------------------------- sub fail { $ftp->quit; die "ftp error occurred\n"; }
_______________________________________________ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs