--===============0609161037==
Content-Type: multipart/alternative; boundary="0-1235879405-1225882620=:35990"
--0-1235879405-1225882620=:35990
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
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 ( [at] models) loop it goes thru" one of three models. =
In model1 it copies from one directory to the local directory =3D"/home/Mum=
ba/ARCHIVE/model/date (date is today's date eg 20081105)
In model2 it has to copy from two directories to two local directories =3D"=
/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 an=
d for model2, thus replacing what was earlier copied.
=A0
How do I define more local directories so that they can be changed in the=
=A0"foreach $rdir ( [at] remotedirs)" loop?
=A0
Assistance will be appreciated.
Zilore
$remote_basedir=3D"/home/synergie";
$datadir=3D"/data/grib";
$local_basedir=3D"/home/Mumba/ARCHIVE";
[at] models=3D("arpege", "ukmo", "ecmf");
$dat=3D`date +%Y%m%d`; chomp $dat;
=A0
# this is a guess so that we don't have to manually edit the script
# and input the cycle each time
$hr=3D`date +%H`; chomp $hr;
if ( $hr > 15 ) { $cycle=3D"12"; }
else { $cycle=3D"00"; }
=A0
# connect to the remote host
#
print "Connecting to $Host ...\n";
$ftp =3D Net::FTP->new($Host, Timeout =3D> 360, Passive=3D>"true") || &fail=
;
$ftp->login($User,$Pass) ;
$ftp->binary ;
$ftp->cwd($datadir);
=A0
# retrieve data
#
print "Copying data\n";
foreach $model ( [at] models) {
=A0=A0 # define local and remote directories before copying files
=A0=A0 #
=A0=A0 $localdir=3D"$local_basedir/$model/$dat";
=A0=A0 undef [at] remotedirs;
=A0=A0 if ( "$model" eq "arpege" ) {
=A0=A0=A0=A0=A0 $remotedir=3D"${remote_basedir}${datadir}/PS.R2kAF15/${dat}=
${cycle}0000";
=A0=A0=A0=A0=A0 push ( [at] remotedirs, $remotedir);
=A0=A0 }
=A0=A0 elsif ( "$model" eq "ukmo" ) {
=A0=A0=A0=A0=A0 $remotedir=3D"${remote_basedir}${datadir}/UK2.G41/${dat}${c=
ycle}0000";
=A0=A0=A0=A0=A0 push ( [at] remotedirs, $remotedir);
=A0=A0=A0=A0=A0 $remotedir=3D"${remote_basedir}${datadir}/UK2.G37/${dat}${c=
ycle}0000";
=A0=A0=A0=A0=A0 push ( [at] remotedirs, $remotedir);
=A0=A0 }
=A0=A0 elsif ( "$model" eq "ecmf") {
=A0=A0=A0=A0=A0 $remotedir=3D"${remote_basedir}${datadir}/PC.G25/${dat}${cy=
cle}0000";
=A0=A0=A0=A0=A0 push ( [at] remotedirs, $remotedir);
=A0=A0=A0=A0=A0 $remotedir=3D"${remote_basedir}${datadir}/PC.G28/${dat}${cy=
cle}0000";
=A0=A0=A0=A0=A0 push ( [at] remotedirs, $remotedir);
=A0=A0=A0=A0=A0 $remotedir=3D"${remote_basedir}${datadir}/PC.G29/${dat}${cy=
cle}0000";
=A0=A0=A0=A0=A0 push ( [at] remotedirs, $remotedir);
=A0=A0=A0=A0=A0 $remotedir=3D"${remote_basedir}${datadir}/PC.G32/${dat}${cy=
cle}0000";
=A0=A0=A0=A0=A0 push ( [at] remotedirs, $remotedir);
=A0=A0 }
=A0
=A0=A0 if (! -d $localdir ) { system("mkdir -p $localdir"); }
=A0=A0 chdir $localdir;
=A0
=A0=A0 # retrieve files
=A0=A0 #
=A0=A0 foreach $rdir ( [at] remotedirs) {
=A0=A0=A0=A0=A0 print "Retrieving files from $rdir to $localdir\n";
=A0
=A0=A0=A0=A0=A0 $ftp->cwd($rdir);
=A0=A0=A0=A0=A0 # perl/ftp doesn't support mget, so we have to get a list
=A0=A0=A0=A0=A0 # and *then* get the files :(
=A0=A0=A0=A0=A0 #
=A0=A0=A0=A0=A0 [at] files =3D $ftp->ls;
=A0=A0=A0=A0=A0 foreach $file ( [at] files) {
=A0=A0=A0=A0=A0=A0=A0 $ftp->get($file);
=A0=A0=A0=A0=A0 }
=A0=A0 }
}
$ftp->close;
print "copying ends\n";
exit 0;
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=
=3D=3D
#=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A 0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0 Subroutines
#----------------------------------------------------------- ---------------=
--
sub fail {
=A0=A0=A0 $ftp->quit;
=A0=A0=A0 die "ftp error occurred\n";
}
=0A=0A=0A
--0-1235879405-1225882620=:35990
Content-Type: text/html; charset=us-ascii
<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>Assistance sought. Below i have a programme which copies files by ftp. The programme works. Here's what it does</DIV>
<DIV>.1 in the foreach $model ( [at] 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)</DIV>
<DIV>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</DIV>
<DIV>In model3 it has to copy from 4 remote directories.</DIV>
<DIV>Currently it is putting all files in the same local directory for model1 and for model2, thus replacing what was earlier copied.</DIV>
<DIV> </DIV>
<DIV>How do I define more local directories so that they can be changed in the "foreach $rdir ( [at] remotedirs)" loop?</DIV>
<DIV> </DIV>
<DIV>Assistance will be appreciated.</DIV>
<DIV>Zilore</DIV>
<DIV><BR>$remote_basedir="/home/synergie";<BR>$datadir="/data/grib";<BR>$local_basedir="/home/Mumba/ARCHIVE";</DIV>
<DIV> [at] models=("arpege", "ukmo", "ecmf");</DIV>
<DIV>$dat=`date +%Y%m%d`; chomp $dat;</DIV>
<DIV> </DIV>
<DIV># this is a guess so that we don't have to manually edit the script<BR># and input the cycle each time<BR>$hr=`date +%H`; chomp $hr;<BR>if ( $hr > 15 ) { $cycle="12"; }<BR>else { $cycle="00"; }</DIV>
<DIV> </DIV>
<DIV># connect to the remote host<BR>#<BR>print "Connecting to $Host ...\n";<BR>$ftp = Net::FTP->new($Host, Timeout => 360, Passive=>"true") || &fail ;<BR>$ftp->login($User,$Pass) ;<BR>$ftp->binary ;</DIV>
<DIV>$ftp->cwd($datadir);</DIV>
<DIV> </DIV>
<DIV># retrieve data<BR>#<BR>print "Copying data\n";</DIV>
<DIV>foreach $model ( [at] models) {</DIV>
<DIV> # define local and remote directories before copying files<BR> #<BR> $localdir="$local_basedir/$model/$dat";</DIV>
<DIV> undef [at] remotedirs;</DIV>
<DIV> if ( "$model" eq "arpege" ) {<BR> $remotedir="${remote_basedir}${datadir}/PS.R2kAF15/${dat}${c ycle}0000";<BR> push ( [at] remotedirs, $remotedir);<BR> } <BR> elsif ( "$model" eq "ukmo" ) {<BR> $remotedir="${remote_basedir}${datadir}/UK2.G41/${dat}${cycl e}0000";<BR> push ( [at] remotedirs, $remotedir);<BR> $remotedir="${remote_basedir}${datadir}/UK2.G37/${dat}${cycl e}0000";<BR> push ( [at] remotedirs, $remotedir);<BR> }<BR> elsif ( "$model" eq "ecmf") {<BR> $remotedir="${remote_basedir}${datadir}/PC.G25/${dat}${cycle }0000";<BR> &
nbsp; push ( [at] remotedirs, $remotedir);<BR>
$remotedir="${remote_basedir}${datadir}/PC.G28/${dat}${cycle }0000";<BR> push ( [at] remotedirs, $remotedir);<BR> $remotedir="${remote_basedir}${datadir}/PC.G29/${dat}${cycle }0000";<BR> push ( [at] remotedirs, $remotedir);<BR> $remotedir="${remote_basedir}${datadir}/PC.G32/${dat}${cycle }0000";<BR> push ( [at] remotedirs, $remotedir);<BR> }<BR> <BR> if (! -d $localdir ) { system("mkdir -p $localdir"); }<BR> chdir $localdir;<BR> <BR> # retrieve files<BR> #<BR> foreach $rdir ( [at] remotedirs) { </DIV>
<DIV> print "Retrieving files from $rdir to $localdir\n";<BR> <BR> $ftp->cwd($rdir);</DIV>
<DIV> # perl/ftp doesn't support mget, so we have to get a list<BR> # and *then* get the files :(<BR> #<BR> [at] files = $ftp->ls;<BR> foreach $file ( [at] files) { <BR> $ftp->get($file);<BR> }</DIV>
<DIV> }<BR>}<BR>$ftp->close; <BR>print "copying ends\n";<BR>exit 0;</DIV>
<DIV> #=========================================================== =================<BR># Subroutines<BR> #----------------------------------------------------------- -----------------<BR>sub fail {<BR> $ftp->quit;<BR> die "ftp error occurred\n";<BR>}<BR><BR></DIV></td></tr></table><br>
--0-1235879405-1225882620=:35990--
--===============0609161037==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0609161037==--
