help with ftp

help with ftp

am 29.12.2009 13:00:57 von zilore mumba

--===============1099479942==
Content-Type: multipart/alternative; boundary="0-1133406087-1262088057=:71565"

--0-1133406087-1262088057=:71565
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hello Perl Community.
Thanks so much for all the help provided lduring the current year.
Happy and prosperous New Year 2010 to all.

Below is my code where I have a problem with ftp. I am trying to transfer d=
ata from one PC to another. When I try to make a directory on the distant m=
achine, I get the error: "Can't locate object method 'mkpath' via package '=
ftp".
When I comment this part out, the same error appears later on with "ftp->pu=
t".
Both parts with problem are highlighted in yellow.

I am not able to find help in Perldoc.
Any help will be appreciated

Zilore


#!/usr/bin/perl -w
#This transfers files from a=A0 PC running LINUX to Windows PC.
#
use Net::FTP;

use strict;
use warnings;
use POSIX;
use File::Path;
use File::Copy;

my $debug =3D 1;
# set variables
#
my $User =3D 'pc-mis';
my $Pass =3D 'acmad11';
my $Host =3D '192.168.2.115';

my @models =3D ('arpege', 'ukmo', 'ecmf');
my @now =3D localtime;
my $dat =3D strftime "%Y%m%d", @now;
my $mon_ab =3D strftime "%b",@now;
my $mon_num =3D strftime "%m",@now;
my $mon_name =3D strftime "%B",@now;
my $yr=3Dstrftime "%y",@now;

my $dash=3D"-";
my $mod =3D "models";

my ($day, $month, $year) =3D (localtime(time() - 60 * 60 * 24)) [ 3, 4, 5 ]=
;
$year =3D $year+1900;
$month =3D $month+1;

my $dat0 =3D sprintf("%04d%02d%02d",=A0 $year, $month, $day );

my $archive_dir =3D "../ARCHIVE/$mon_num$dash$mon_name$yr";   # where d=
ata is

my $remote_basedir =3D '/';
my $data_dir =3D "ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mod"; #=
where to put it

my @localdir =3D("../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]/$dat0",
               "../ARCHIVE/$mon_num$dash$mon_na=
me$yr/$models[1]/$dat0",
  =A0   =A0   =A0    "../ARCHIVE/$mon_num$dash$mon_name$yr/=
$models[2]/$dat0");=20

#my @remotedir =3D ('$data_dir/$models[0]/$dat0','$data_dir/$models[1]/$dat=
0',
#                 '$data_dir/$models[2]/$da=
t0');

# connect to the remote host

print "Connecting to $Host ...\n";
my $ftp =3D Net::FTP->new($Host, Timeout =3D> 360, Passive =3D> 'true') or =
fail ();
   
$ftp->login($User,$Pass) or die " login '$ftp'=A0 failed: $_ ($^E)";
$ftp->binary;

foreach my $ddir (@remotedir) {
  =A0 if (! -d $ddir) {
      =A0 print "mkpath $ddir\n" if $debug;
      =A0 $ftp->mkpath ($ddir) or die "mkpath '$ddir' failed: $=
! ($^E)";
   }
}
$ftp->cwd($data_dir);

# transfer data

print "Transfering data\n";

#my %numbers =3D ('$localdirs[0]' =3D> '0','localdirs[1]' =3D> '1','localdi=
rs[2]' =3D> '2');

my %remotedirs =3D ();
my $remotedirs;
   
foreach my $model (@models) {

  =A0 # define local and remote directories before copying files

  =A0 if ($model eq 'arpege') {
     my $remotedirs =3D "$data_dir/$models[0]/$dat0";
  =A0    $remotedirs{$remotedirs} =3D $localdir[0];

=A0 } elsif ($model eq 'ukmo') {
     my $remotedirs =3D "$data_dir/$models[1]/$dat0";
       $remotedirs{$remotedirs} =3D $localdir[1];

=A0 } elsif ($model eq 'ecmf') {
     my $remotedirs =3D "$data_dir/$models[2]/$dat0";
       $remotedirs{$remotedirs} =3D $localdir[2];
=A0 }
 
  =A0 # Transfer files

  =A0 foreach my $rdir (keys %remotedirs) {
  =A0 =A0$ftp->cwd($remotedirs($rdir));

     my $ldir =3D $remotedirs{$rdir}
    =20
  =A0 =A0print "Transfering files from $ldir to $remotedirs(rdir)\n" if=
$debug;
     opendir DIR, "$ldir" or die "opendir '$ldir: $! ($^E)";
     while (my $file =3D readdir DIR) {
      =A0 print "DIR";
      =A0 exit;
      =A0 next if $file =3D~ /\*(b|x|l)$/;
      =A0 print "Putting $file\n" if $debug;
      =A0 ftp->put($file) or warn "Failed '$file': $! ($^E)";
     }
     closedir DIR;
 
  =A0 }
}

$ftp->close;
print "Transfering ends\n";
exit 0;

#===================3D=3 D=====
==================== =====3D=
==================== =====3D=
==
#                  =A0=A 0    =
      =A0 Subroutines
#===================3D=3 D=====
==================== =====3D=
==================== =====3D=
==

sub fail {

$ftp->quit;
die "ftp error occurred\n";

}


__END__

my $files =3D $ftp->dir() or die "Error doing ftp->dir: $!\n";
my $files =3D dir() or die "Error doing dir: $!\n";
foreach (@$files) {
  =A0 # skip lines not starting with d or -
  =A0 if (/^[^d-]/) {
         print "Skipping garbage dir line\n" if $debug;
      =A0 next;
  =A0 }

# ftp dir listing
#----0----- -1- ---2---- ---3---- ---4---- -5- -6 --7-- -----8--------
#total 52
#drwx--x---   3 owner  =A0 group      =A0 1024 Dec 13=
=A0 1997 .
#drwxr-xr-x 671 owner  =A0 group       49152 Dec 18 14:09 .=
..
#-rw-r--r--   1 xyz    =A0 httpd      =A0 2010 Sep =
21 13:31 index.htm

  =A0 my ($size, $file) =3D (split /\s+/, $_, 9)[4,8];  =A0 # get s=
ize/filename
  =A0 next if $file =3D~ /^\.{1,2}$/;      =A0 # skip . and=
..

  =A0 # if directory - call directory recurse routine

  =A0 if (/^d/) {
      =A0 ...


=0A
--0-1133406087-1262088057=:71565
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

able>

--0-1133406087-1262088057=:71565--

--===============1099479942==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1099479942==--

RE: help with ftp

am 29.12.2009 15:45:25 von Jeff Saxton

--===============1205395663==
Content-Language: en-US
Content-Type: multipart/alternative;
boundary="_000_6DFE695E783E004A9E6D2CD1E0B8CA1F0BED995FD8bma il2bigfixc_"

--_000_6DFE695E783E004A9E6D2CD1E0B8CA1F0BED995FD8bmail2bigfi xc_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

from the pod:

mkdir ( DIR [, RECURSE ])

Create a new directory with the name DIR. If RECURSE is true then mkdir wil=
l attempt to create all the directories in the given path.





________________________________
From: activeperl-bounces@listserv.ActiveState.com [activeperl-bounces@lists=
erv.ActiveState.com] On Behalf Of zilore mumba [zmumba@yahoo.com]
Sent: Tuesday, December 29, 2009 6:00 AM
To: activeperl@listserv.activestate.com
Subject: help with ftp

Hello Perl Community.
Thanks so much for all the help provided lduring the current year.
Happy and prosperous New Year 2010 to all.

Below is my code where I have a problem with ftp. I am trying to transfer d=
ata from one PC to another. When I try to make a directory on the distant m=
achine, I get the error: "Can't locate object method 'mkpath' via package '=
ftp".
When I comment this part out, the same error appears later on with "ftp->pu=
t".
Both parts with problem are highlighted in yellow.

I am not able to find help in Perldoc.
Any help will be appreciated

Zilore


#!/usr/bin/perl -w
#This transfers files from a PC running LINUX to Windows PC.
#
use Net::FTP;

use strict;
use warnings;
use POSIX;
use File::Path;
use File::Copy;

my $debug =3D 1;
# set variables
#
my $User =3D 'pc-mis';
my $Pass =3D 'acmad11';
my $Host =3D '192.168.2.115';

my @models =3D ('arpege', 'ukmo', 'ecmf');
my @now =3D localtime;
my $dat =3D strftime "%Y%m%d", @now;
my $mon_ab =3D strftime "%b",@now;
my $mon_num =3D strftime "%m",@now;
my $mon_name =3D strftime "%B",@now;
my $yr=3Dstrftime "%y",@now;

my $dash=3D"-";
my $mod =3D "models";

my ($day, $month, $year) =3D (localtime(time() - 60 * 60 * 24)) [ 3, 4, 5 ]=
;
$year =3D $year+1900;
$month =3D $month+1;

my $dat0 =3D sprintf("%04d%02d%02d", $year, $month, $day );

my $archive_dir =3D "../ARCHIVE/$mon_num$dash$mon_name$yr"; # where data =
is

my $remote_basedir =3D '/';
my $data_dir =3D "ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mod"; #=
where to put it

my @localdir =3D("../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]/$dat0",
"../ARCHIVE/$mon_num$dash$mon_name$yr/$models[1]/$dat0",
"../ARCHIVE/$mon_num$dash$mon_name$yr/$models[2]/$dat0");

#my @remotedir =3D ('$data_dir/$models[0]/$dat0','$data_dir/$models[1]/$dat=
0',
# '$data_dir/$models[2]/$dat0');

# connect to the remote host

print "Connecting to $Host ...\n";
my $ftp =3D Net::FTP->new($Host, Timeout =3D> 360, Passive =3D> 'true') or =
fail ();

$ftp->login($User,$Pass) or die " login '$ftp' failed: $_ ($^E)";
$ftp->binary;

foreach my $ddir (@remotedir) {
if (! -d $ddir) {
print "mkpath $ddir\n" if $debug;
$ftp->mkpath ($ddir) or die "mkpath '$ddir' failed: $! ($^E)";
}
}
$ftp->cwd($data_dir);

# transfer data

print "Transfering data\n";

#my %numbers =3D ('$localdirs[0]' =3D> '0','localdirs[1]' =3D> '1','localdi=
rs[2]' =3D> '2');

my %remotedirs =3D ();
my $remotedirs;

foreach my $model (@models) {

# define local and remote directories before copying files

if ($model eq 'arpege') {
my $remotedirs =3D "$data_dir/$models[0]/$dat0";
$remotedirs{$remotedirs} =3D $localdir[0];

} elsif ($model eq 'ukmo') {
my $remotedirs =3D "$data_dir/$models[1]/$dat0";
$remotedirs{$remotedirs} =3D $localdir[1];

} elsif ($model eq 'ecmf') {
my $remotedirs =3D "$data_dir/$models[2]/$dat0";
$remotedirs{$remotedirs} =3D $localdir[2];
}

# Transfer files

foreach my $rdir (keys %remotedirs) {
$ftp->cwd($remotedirs($rdir));

my $ldir =3D $remotedirs{$rdir}

print "Transfering files from $ldir to $remotedirs(rdir)\n" if $debug;
opendir DIR, "$ldir" or die "opendir '$ldir: $! ($^E)";
while (my $file =3D readdir DIR) {
print "DIR";
exit;
next if $file =3D~ /\*(b|x|l)$/;
print "Putting $file\n" if $debug;
ftp->put($file) or warn "Failed '$file': $! ($^E)";
}
closedir DIR;

}
}

$ftp->close;
print "Transfering ends\n";
exit 0;

#===================3D=3 D=====
==================== =====3D=
==================== =====3D=
==
# Subroutines
#===================3D=3 D=====
==================== =====3D=
==================== =====3D=
==

sub fail {

$ftp->quit;
die "ftp error occurred\n";

}


__END__

my $files =3D $ftp->dir() or die "Error doing ftp->dir: $!\n";
my $files =3D dir() or die "Error doing dir: $!\n";
foreach (@$files) {
# skip lines not starting with d or -
if (/^[^d-]/) {
print "Skipping garbage dir line\n" if $debug;
next;
}

# ftp dir listing
#----0----- -1- ---2---- ---3---- ---4---- -5- -6 --7-- -----8--------
#total 52
#drwx--x--- 3 owner group 1024 Dec 13 1997 .
#drwxr-xr-x 671 owner group 49152 Dec 18 14:09 ..
#-rw-r--r-- 1 xyz httpd 2010 Sep 21 13:31 index.htm

my ($size, $file) =3D (split /\s+/, $_, 9)[4,8]; # get size/filename
next if $file =3D~ /^\.{1,2}$/; # skip . and ..

# if directory - call directory recurse routine

if (/^d/) {
...





--_000_6DFE695E783E004A9E6D2CD1E0B8CA1F0BED995FD8bmail2bigfi xc_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


1">




from th=
e pod:

 

mkdir ( DIR [, R=
ECURSE ])


Create a new directory with the name DIR. If RECURSE<=
/code> is
true then mkdir will attempt to create all the director=
ies in the given path.



 


 





From: activeperl-bounces@listserv.A=
ctiveState.com [activeperl-bounces@listserv.ActiveState.com] On Behalf Of z=
ilore mumba [zmumba@yahoo.com]

Sent: Tuesday, December 29, 2009 6:00 AM

To: activeperl@listserv.activestate.com

Subject: help with ftp






top" style=3D"font: inherit;">Hello Perl Community.
Thanks so much for a=
ll the help provided lduring the current year.
Happy and prosperous New =
Year 2010 to all.

Below is my code where I have a problem with ftp. =
I am trying to transfer data from one PC to another. When I try to make a d=
irectory on the distant machine, I get the error: "Can't locate object meth=
od 'mkpath' via package 'ftp".
When I comment this part out, the same er=
ror appears later on with "ftp->put".
Both parts with problem are hig=
hlighted in yellow.

I am not able to find help in Perldoc.
Any he=
lp will be appreciated

Zilore


#!/usr/bin/perl -w
#This=
transfers files from a  PC running LINUX to Windows PC.
#
use N=
et::FTP;

use strict;
use warnings;
use POSIX;
use File::Pat=
h;
use File::Copy;

my $debug =3D 1;
# set variables
#
my
$User =3D 'pc-mis';
my $Pass =3D 'acmad11';
my $Host =3D '192.168.2.=
115';

my @models =3D ('arpege', 'ukmo', 'ecmf');
my @now =3D loca=
ltime;
my $dat =3D strftime "%Y%m%d", @now;
my $mon_ab =3D strftime "=
%b",@now;
my $mon_num =3D strftime "%m",@now;
my $mon_name =3D strfti=
me "%B",@now;
my $yr=3Dstrftime "%y",@now;

my $dash=3D"-";
my =
$mod =3D "models";

my ($day, $month, $year) =3D (localtime(time() - =
60 * 60 * 24)) [ 3, 4, 5 ];
$year =3D $year+1900;
$month =3D $month+1=
;

my $dat0 =3D sprintf("%04d%02d%02d",  $year, $month, $day );<=
br>
my $archive_dir =3D "../ARCHIVE/$mon_num$dash$mon_name$yr"; &nb=
sp; # where data is

my $remote_basedir =3D '/';
my $data_dir =3D =
"ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mod"; #where to put it r>
my @localdir =3D("../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]/$da=
t0",
           &=
nbsp;  
"../ARCHIVE/$mon_num$dash$mon_name$yr/$models[1]/$dat0",
  &n=
bsp;            "../ARCHIVE/$mon_nu=
m$dash$mon_name$yr/$models[2]/$dat0");

#my @remotedir =3D ('$data_d=
ir/$models[0]/$dat0','$data_dir/$models[1]/$dat0',
#   &n=
bsp;            =
; '$data_dir/$models[2]/$dat0');

# connect to the remote host
>print "Connecting to $Host ...\n";
my $ftp =3D Net::FTP->new($Host, =
Timeout =3D> 360, Passive =3D> 'true') or fail ();
  &nb=
sp;
$ftp->login($User,$Pass) or die " login '$ftp'  failed: $_ =
($^E)";
$ftp->binary;

, 255, 0);">foreach my $ddir (@remotedir) {
olor: rgb(255, 255, 0);"> ">    if (! -d $ddir) {
rgb(255,
255, 0);">  =
      print "mkpath $ddir\n" if $debug;

style=3D"background-color: rgb(255, 255, 0);"> or: rgb(255, 255, 0);">        $ftp->=
mkpath ($ddir) or die "mkpath '$ddir' failed: $! ($^E)";

"background-color: rgb(255, 255, 0);"> 255, 255, 0);">   }
255, 0);">}
=
$ftp->cwd($data_dir);

# transfer data

print "Transfering d=
ata\n";

#my %numbers =3D ('$localdirs[0]' =3D> '0','localdirs[1]'=
=3D> '1','localdirs[2]' =3D> '2');

my %remotedirs =3D ();
=
my $remotedirs;
   
foreach my $model (@models) {
=

    # define local and remote directories before copying
files

    if ($model eq 'arpege') {
  &=
nbsp;  my $remotedirs =3D "$data_dir/$models[0]/$dat0";
  =
;     $remotedirs{$remotedirs} =3D $localdir[0];

&nbs=
p; } elsif ($model eq 'ukmo') {
     my $remotedirs =
=3D "$data_dir/$models[1]/$dat0";
       $=
remotedirs{$remotedirs} =3D $localdir[1];

  } elsif ($model eq =
'ecmf') {
     my $remotedirs =3D "$data_dir/$models=
[2]/$dat0";
       $remotedirs{$remotedirs=
} =3D $localdir[2];
  }
 
    # Transfer=
files

    foreach my $rdir (keys %remotedirs) {
&=
nbsp;    $ftp->cwd($remotedirs($rdir));

 &nbs=
p;   my $ldir =3D $remotedirs{$rdir}
     =

     print "Transfering files from $ldir to
$remotedirs(rdir)\n" if $debug;
     opendir DIR, "=
$ldir" or die "opendir '$ldir: $! ($^E)";
     while=
(my $file =3D readdir DIR) {
       =
print "DIR";
        exit;
 =
       next if $file =3D~ /\*(b|x|l)$/;
&n=
bsp;       print "Putting $file\n" if $debug;=

        lor: rgb(255, 255, 0);">ftp->put($file) or warn "Failed '$file': $! ($^E=
)";

     }
     closed=
ir DIR;
 
    }
}

$ftp->close;
p=
rint "Transfering ends\n";
exit
0;

#===================3D=3 D=3D=
==================== =====3D=
==================== =====3D=
=====3D
#         &=
nbsp;           &nbs=
p;          Subroutines
#=
==================== =====3D=
==================== =====3D=
==================== =====3D=
=3D

sub fail {

$ftp->quit;
die "ftp error occurred\n";<=
br>
}


__END__

my $files =3D $ftp->dir() or die "Err=
or doing ftp->dir: $!\n";
my $files =3D dir() or die "Error doing dir=
: $!\n";
foreach (@$files) {
    # skip lines not star=
ting with d or -
    if (/^[^d-]/) {
   =
;      print "Skipping garbage dir line\n" if $deb=
ug;
        next;
  &nbs=
p; }

# ftp dir listing
#----0----- -1- ---2---- ---3---- ---4----
-5- -6 --7-- -----8--------
#total 52
#drwx--x---   3 owne=
r    group        1024 De=
c 13  1997 .
#drwxr-xr-x 671 owner    group &nb=
sp;     49152 Dec 18 14:09 ..
#-rw-r--r--  =
; 1 xyz      httpd     &n=
bsp;  2010 Sep 21 13:31 index.htm

    my ($size,=
$file) =3D (split /\s+/, $_, 9)[4,8];    # get size/filenam=
e
    next if $file =3D~ /^\.{1,2}$/;   &n=
bsp;    # skip . and ..

    # if direc=
tory - call directory recurse routine

    if (/^d/) {=

        ...








Hello Perl Community.

Thanks so much for all the help provided lduring the current year.

Happy and prosperous New Year 2010 to all.



Below is my code where I have a problem with ftp. I am trying to transfer d=
ata from one PC to another. When I try to make a directory on the distant m=
achine, I get the error: "Can't locate object method 'mkpath' via pack=
age 'ftp".

When I comment this part out, the same error appears later on with "ft=
p->put".

Both parts with problem are highlighted in yellow.



I am not able to find help in Perldoc.

Any help will be appreciated



Zilore





#!/usr/bin/perl -w

#This transfers files from a  PC running LINUX to Windows PC.

#

use Net::FTP;



use strict;

use warnings;

use POSIX;

use File::Path;

use File::Copy;



my $debug =3D 1;

# set variables

#

my $User =3D 'pc-mis';

my $Pass =3D 'acmad11';

my $Host =3D '192.168.2.115';



my @models =3D ('arpege', 'ukmo', 'ecmf');

my @now =3D localtime;

my $dat =3D strftime "%Y%m%d", @now;

my $mon_ab =3D strftime "%b",@now;

my $mon_num =3D strftime "%m",@now;

my $mon_name =3D strftime "%B",@now;

my $yr=3Dstrftime "%y",@now;



my $dash=3D"-";

my $mod =3D "models";



my ($day, $month, $year) =3D (localtime(time() - 60 * 60 * 24)) [ 3, 4, 5 ]=
;

$year =3D $year+1900;

$month =3D $month+1;



my $dat0 =3D sprintf("%04d%02d%02d",  $year, $month, $day );=




my $archive_dir =3D "../ARCHIVE/$mon_num$dash$mon_name$yr"; =
  # where data is



my $remote_basedir =3D '/';

my $data_dir =3D "ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mo=
d"; #where to put it



my @localdir =3D("../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]/$dat=
0",

            &nb=
sp;  "../ARCHIVE/$mon_num$dash$mon_name$yr/$models[1]/$dat0"=
,

               "=
;../ARCHIVE/$mon_num$dash$mon_name$yr/$models[2]/$dat0");



#my @remotedir =3D ('$data_dir/$models[0]/$dat0','$data_dir/$models[1]/$dat=
0',

#            &n=
bsp;    '$data_dir/$models[2]/$dat0');



# connect to the remote host



print "Connecting to $Host ...\n";

my $ftp =3D Net::FTP->new($Host, Timeout =3D> 360, Passive =3D> 't=
rue') or fail ();

   

$ftp->login($User,$Pass) or die " login '$ftp'  failed: $_ ($^=
E)";

$ftp->binary;



foreach my $ddir (@remoted=
ir) {


    if (! -=
d $ddir) {


    &n=
bsp;   print "mkpath $ddir\n" if $debug;

e=3D"BACKGROUND-COLOR: rgb(255,255,0)">
    &n=
bsp;   $ftp->mkpath ($ddir) or die "mkpath '$ddir' failed=
: $! ($^E)";


   }
tyle=3D"BACKGROUND-COLOR: rgb(255,255,0)">
}

$ftp->cwd($data_dir);



# transfer data



print "Transfering data\n";



#my %numbers =3D ('$localdirs[0]' =3D> '0','localdirs[1]' =3D> '1','l=
ocaldirs[2]' =3D> '2');



my %remotedirs =3D ();

my $remotedirs;

   

foreach my $model (@models) {



    # define local and remote directories before copying fil=
es



    if ($model eq 'arpege') {

     my $remotedirs =3D "$data_dir/$models[0]/$dat=
0";

       $remotedirs{$remotedirs} =3D $localdir[0];<=
br>


  } elsif ($model eq 'ukmo') {

     my $remotedirs =3D "$data_dir/$models[1]/$dat=
0";

       $remotedirs{$remotedirs} =3D $localdir=
[1];



  } elsif ($model eq 'ecmf') {

     my $remotedirs =3D "$data_dir/$models[2]/$dat=
0";

       $remotedirs{$remotedirs} =3D $localdir=
[2];

  }

 

    # Transfer files



    foreach my $rdir (keys %remotedirs) {

     $ftp->cwd($remotedirs($rdir));



     my $ldir =3D $remotedirs{$rdir}

    

     print "Transfering files from $ldir to $remot=
edirs(rdir)\n" if $debug;

     opendir DIR, "$ldir" or die "opendi=
r '$ldir: $! ($^E)";

     while (my $file =3D readdir DIR) {

        print "DIR";

        exit;

        next if $file =3D~ /\*(b|x|l)$/;=


        print "Putting $file\n"=
; if $debug;

        rgb(255,255,0)">ftp->put($file) or warn "Failed '$file': $! ($^E)&=
quot;;


     }

     closedir DIR;

 

    }

}



$ftp->close;

print "Transfering ends\n";

exit 0;



#===================3D=3 D=====
==================== =====3D=
==================== =====3D=
==

#            &n=
bsp;            =
;       Subroutines

#===================3D=3 D=====
==================== =====3D=
==================== =====3D=
==



sub fail {



$ftp->quit;

die "ftp error occurred\n";



}





__END__



my $files =3D $ftp->dir() or die "Error doing ftp->dir: $!\n&quo=
t;;

my $files =3D dir() or die "Error doing dir: $!\n";

foreach (@$files) {

    # skip lines not starting with d or -

    if (/^[^d-]/) {

         print "Skipping garba=
ge dir line\n" if $debug;

        next;

    }



# ftp dir listing

#----0----- -1- ---2---- ---3---- ---4---- -5- -6 --7-- -----8--------

#total 52

#drwx--x---   3 owner    group   &n=
bsp;    1024 Dec 13  1997 .

#drwxr-xr-x 671 owner    group     =
  49152 Dec 18 14:09 ..

#-rw-r--r--   1 xyz      httpd &nbs=
p;      2010 Sep 21 13:31 index.htm



    my ($size, $file) =3D (split /\s+/, $_, 9)[4,8];&nbs=
p;   # get size/filename

    next if $file =3D~ /^\.{1,2}$/;    &=
nbsp;   # skip . and ..



    # if directory - call directory recurse routine



    if (/^d/) {

        ...












--_000_6DFE695E783E004A9E6D2CD1E0B8CA1F0BED995FD8bmail2bigfi xc_--

--===============1205395663==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1205395663==--

RE: help with ftp

am 29.12.2009 17:48:57 von Curtis Leach

This is a multi-part message in MIME format.

--===============1653116433==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01CA88A6.D767EADA"

This is a multi-part message in MIME format.

------_=_NextPart_001_01CA88A6.D767EADA
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: quoted-printable

Another bug, the "if (! -d $ddir)" command in your highlighted foreach
loop checks your local hard drive to see if the directory exists, not
the remote server you are connecting to, which is what I assume you
meant.
=20
I don't see a check if directory or file exists command, so you'd have
to cwd() to that dir & verify it succeeded, or parse what's returned by
list() or nlst(). If it failed, then you can assume the directory
doesn't exist.
=20
As for your 2nd highlighted block, you said "ftp->put" instead of
"$ftp->put". Makes a world of difference.
=20
________________________________

From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of Jeff
Saxton
Sent: Tuesday, December 29, 2009 6:45 AM
To: zilore mumba; activeperl@listserv.activestate.com
Subject: RE: help with ftp


from the pod:
=20
mkdir ( DIR [, RECURSE ])=20
Create a new directory with the name DIR. If RECURSE is true then mkdir
will attempt to create all the directories in the given path.

=20

=20

________________________________

From: activeperl-bounces@listserv.ActiveState.com
[activeperl-bounces@listserv.ActiveState.com] On Behalf Of zilore mumba
[zmumba@yahoo.com]
Sent: Tuesday, December 29, 2009 6:00 AM
To: activeperl@listserv.activestate.com
Subject: help with ftp


Hello Perl Community.
Thanks so much for all the help provided lduring the current year.
Happy and prosperous New Year 2010 to all.

Below is my code where I have a problem with ftp. I am trying to
transfer data from one PC to another. When I try to make a directory on
the distant machine, I get the error: "Can't locate object method
'mkpath' via package 'ftp".
When I comment this part out, the same error appears later on with
"ftp->put".
Both parts with problem are highlighted in yellow.

I am not able to find help in Perldoc.
Any help will be appreciated

Zilore


#!/usr/bin/perl -w
#This transfers files from a PC running LINUX to Windows PC.
#
use Net::FTP;

use strict;
use warnings;
use POSIX;
use File::Path;
use File::Copy;

my $debug =3D 1;
# set variables
#
my $User =3D 'pc-mis';
my $Pass =3D 'acmad11';
my $Host =3D '192.168.2.115';

my @models =3D ('arpege', 'ukmo', 'ecmf');
my @now =3D localtime;
my $dat =3D strftime "%Y%m%d", @now;
my $mon_ab =3D strftime "%b",@now;
my $mon_num =3D strftime "%m",@now;
my $mon_name =3D strftime "%B",@now;
my $yr=3Dstrftime "%y",@now;

my $dash=3D"-";
my $mod =3D "models";

my ($day, $month, $year) =3D (localtime(time() - 60 * 60 * 24)) [ 3, 4, =
5
];
$year =3D $year+1900;
$month =3D $month+1;

my $dat0 =3D sprintf("%04d%02d%02d", $year, $month, $day );

my $archive_dir =3D "../ARCHIVE/$mon_num$dash$mon_name$yr"; # where =
data
is

my $remote_basedir =3D '/';
my $data_dir =3D =
"ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mod";
#where to put it

my @localdir =
=3D("../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]/$dat0",
"../ARCHIVE/$mon_num$dash$mon_name$yr/$models[1]/$dat0",
"../ARCHIVE/$mon_num$dash$mon_name$yr/$models[2]/$dat0");


#my @remotedir =3D
('$data_dir/$models[0]/$dat0','$data_dir/$models[1]/$dat0',
# '$data_dir/$models[2]/$dat0');

# connect to the remote host

print "Connecting to $Host ...\n";
my $ftp =3D Net::FTP->new($Host, Timeout =3D> 360, Passive =3D> 'true') =
or
fail ();
=20
$ftp->login($User,$Pass) or die " login '$ftp' failed: $_ ($^E)";
$ftp->binary;

foreach my $ddir (@remotedir) {
if (! -d $ddir) {
print "mkpath $ddir\n" if $debug;
$ftp->mkpath ($ddir) or die "mkpath '$ddir' failed: $! ($^E)";
}
}
$ftp->cwd($data_dir);

# transfer data

print "Transfering data\n";

#my %numbers =3D ('$localdirs[0]' =3D> '0','localdirs[1]' =3D>
'1','localdirs[2]' =3D> '2');

my %remotedirs =3D ();
my $remotedirs;
=20
foreach my $model (@models) {

# define local and remote directories before copying files

if ($model eq 'arpege') {
my $remotedirs =3D "$data_dir/$models[0]/$dat0";
$remotedirs{$remotedirs} =3D $localdir[0];

} elsif ($model eq 'ukmo') {
my $remotedirs =3D "$data_dir/$models[1]/$dat0";
$remotedirs{$remotedirs} =3D $localdir[1];

} elsif ($model eq 'ecmf') {
my $remotedirs =3D "$data_dir/$models[2]/$dat0";
$remotedirs{$remotedirs} =3D $localdir[2];
}
=20
# Transfer files

foreach my $rdir (keys %remotedirs) {
$ftp->cwd($remotedirs($rdir));

my $ldir =3D $remotedirs{$rdir}
=20
print "Transfering files from $ldir to $remotedirs(rdir)\n" if
$debug;
opendir DIR, "$ldir" or die "opendir '$ldir: $! ($^E)";
while (my $file =3D readdir DIR) {
print "DIR";
exit;
next if $file =3D~ /\*(b|x|l)$/;
print "Putting $file\n" if $debug;
ftp->put($file) or warn "Failed '$file': $! ($^E)";
}
closedir DIR;
=20
}
}

$ftp->close;
print "Transfering ends\n";
exit 0;

#===================3D=3 D=====
==================== =====3D=
==================== ==
=====3D
# Subroutines
#===================3D=3 D=====
==================== =====3D=
==================== ==
=====3D

sub fail {

$ftp->quit;
die "ftp error occurred\n";

}


__END__

my $files =3D $ftp->dir() or die "Error doing ftp->dir: $!\n";
my $files =3D dir() or die "Error doing dir: $!\n";
foreach (@$files) {
# skip lines not starting with d or -
if (/^[^d-]/) {
print "Skipping garbage dir line\n" if $debug;
next;
}

# ftp dir listing
#----0----- -1- ---2---- ---3---- ---4---- -5- -6 --7-- -----8--------
#total 52
#drwx--x--- 3 owner group 1024 Dec 13 1997 .
#drwxr-xr-x 671 owner group 49152 Dec 18 14:09 ..
#-rw-r--r-- 1 xyz httpd 2010 Sep 21 13:31 index.htm

my ($size, $file) =3D (split /\s+/, $_, 9)[4,8]; # get
size/filename
next if $file =3D~ /^\.{1,2}$/; # skip . and ..

# if directory - call directory recurse routine

if (/^d/) {
...


=09


------_=_NextPart_001_01CA88A6.D767EADA
Content-Type: text/html;
charset=us-ascii
Content-Transfer-Encoding: quoted-printable



charset=3Dus-ascii">




face=3DArial=20
color=3D#0000ff size=3D2>Another bug, the "if (! -d =
$ddir)
" command=20
in your highlighted foreach loop checks your local hard drive to =
see if the=20
directory exists, not the remote server you are connecting to, which is =
what I=20
assume you meant.

face=3DArial=20
color=3D#0000ff size=3D2>
 

face=3DArial=20
color=3D#0000ff size=3D2>I don't see a check if directory or file =
exists=20
command, so you'd have to cwd() to that dir & verify it succeeded, =
or parse=20
what's returned by list() or nlst().  If it failed, then you can =
assume the=20
directory doesn't exist.

face=3DArial=20
color=3D#0000ff size=3D2>
 

  face=3DArial=20
color=3D#0000ff size=3D2>As for your 2nd highlighted block, you said =
"ftp->put"=20
instead of "$ftp->put".  Makes a world of=20
difference.

face=3DArial=20
color=3D#0000ff size=3D2>
 





From:=20
activeperl-bounces@listserv.ActiveState.com=20
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of =
Jeff=20
Saxton
Sent: Tuesday, December 29, 2009 6:45 AM
To: =
zilore=20
mumba; activeperl@listserv.activestate.com
Subject: RE: help =
with=20
ftp



from the pod:

 


=20

Create a new directory with the name DIR. If=20
RECURSE is true then mkdir will attempt =
to=20
create all the directories in the given path.


 


 





From:=20
activeperl-bounces@listserv.ActiveState.com=20
[activeperl-bounces@listserv.ActiveState.com] On Behalf Of zilore mumba=20
[zmumba@yahoo.com]
Sent: Tuesday, December 29, 2009 6:00=20
AM
To: activeperl@listserv.activestate.com
Subject: =
help=20
with ftp







Hello Perl Community.
Thanks so much for all the =
help=20
provided lduring the current year.
Happy and prosperous New =
Year 2010=20
to all.

Below is my code where I have a problem with ftp. I =
am=20
trying to transfer data from one PC to another. When I try to make =
a=20
directory on the distant machine, I get the error: "Can't locate =
object=20
method 'mkpath' via package 'ftp".
When I comment this part =
out, the=20
same error appears later on with "ftp->put".
Both parts with =
problem=20
are highlighted in yellow.

I am not able to find help in=20
Perldoc.
Any help will be=20
appreciated

Zilore


#!/usr/bin/perl -w
#This =
transfers=20
files from a  PC running LINUX to Windows PC.
#
use=20
Net::FTP;

use strict;
use warnings;
use POSIX;
use =

File::Path;
use File::Copy;

my $debug =3D 1;
# set=20
variables
#
my $User =3D 'pc-mis';
my $Pass =3D =
'acmad11';
my=20
$Host =3D '192.168.2.115';

my @models =3D ('arpege', =
'ukmo',=20
'ecmf');
my @now =3D localtime;
my $dat =3D strftime =
"%Y%m%d",=20
@now;
my $mon_ab =3D strftime "%b",@now;
my $mon_num =3D =
strftime=20
"%m",@now;
my $mon_name =3D strftime "%B",@now;
my =
$yr=3Dstrftime=20
"%y",@now;

my $dash=3D"-";
my $mod =3D =
"models";

my ($day,=20
$month, $year) =3D (localtime(time() - 60 * 60 * 24)) [ 3, 4, 5 =
];
$year=20
=3D $year+1900;
$month =3D $month+1;

my $dat0 =
sprintf("%04d%02d%02d",  $year, $month, $day );

my=20
$archive_dir =3D =
"../ARCHIVE/$mon_num$dash$mon_name$yr";   # where=20
data is

my $remote_basedir =3D '/';
my $data_dir =
"ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mod"; #where to =
put=20
it

my @localdir=20
=
=3D("../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]/$dat0",
 &nb=
sp;           &nbs=
p;=20
=
"../ARCHIVE/$mon_num$dash$mon_name$yr/$models[1]/$dat0",
  &=
nbsp;=20
          =20
"../ARCHIVE/$mon_num$dash$mon_name$yr/$models[2]/$dat0"); =


#my=20
@remotedir =
=
('$data_dir/$models[0]/$dat0','$data_dir/$models[1]/$dat0',
# &nb=
sp;           &nbs=
p;  =20
'$data_dir/$models[2]/$dat0');

# connect to the remote=20
host

print "Connecting to $Host ...\n";
my $ftp =
Net::FTP->new($Host, Timeout =3D> 360, Passive =3D> =
'true') or fail=20
();
   
$ftp->login($User,$Pass) or die " =
login=20
'$ftp'  failed: $_ ($^E)";
$ftp->binary;

style=3D"BACKGROUND-COLOR: rgb(255,255,0)">foreach my $ddir =
(@remotedir)=20
{
style=3D"BACKGROUND-COLOR: rgb(255,255,0)">    if =
(! -d=20
$ddir) {
rgb(255,255,0)"> style=3D"BACKGROUND-COLOR: =
rgb(255,255,0)">       =20
print "mkpath $ddir\n" if $debug; style=3D"BACKGROUND-COLOR: rgb(255,255,0)"> style=3D"BACKGROUND-COLOR: =
rgb(255,255,0)">       =20
$ftp->mkpath ($ddir) or die "mkpath '$ddir' failed: $!=20
($^E)";

style=3D"BACKGROUND-COLOR: rgb(255,255,0)">   =
}
style=3D"BACKGROUND-COLOR: rgb(255,255,0)"> style=3D"BACKGROUND-COLOR: =
rgb(255,255,0)">}
$ftp->cwd($data_dir);

#=20
transfer data

print "Transfering data\n";

#my =
%numbers =
('$localdirs[0]' =3D> '0','localdirs[1]' =3D> =
'1','localdirs[2]' =3D>=20
'2');

my %remotedirs =3D ();
my =
$remotedirs;
   =20

foreach my $model (@models) {

    # =
define local=20
and remote directories before copying =
files

    if=20
($model eq 'arpege') {
     my $remotedirs =
=
"$data_dir/$models[0]/$dat0";
      =20
$remotedirs{$remotedirs} =3D $localdir[0];

  } elsif =
($model eq=20
'ukmo') {
     my $remotedirs =
=
"$data_dir/$models[1]/$dat0";
      =20
$remotedirs{$remotedirs} =3D $localdir[1];

  } elsif =
($model eq=20
'ecmf') {
     my $remotedirs =
=
"$data_dir/$models[2]/$dat0";
      =20
$remotedirs{$remotedirs} =3D $localdir[2];
  }
 =20

    # Transfer files

    =
foreach=20
my $rdir (keys %remotedirs) {
   =20
=
 $ftp->cwd($remotedirs($rdir));

     =
my=20
$ldir =3D $remotedirs{$rdir}
    =20

     print "Transfering files from $ldir =
to=20
$remotedirs(rdir)\n" if $debug;
     =
opendir DIR,=20
"$ldir" or die "opendir '$ldir: $! =
($^E)";
    =20
while (my $file =3D readdir DIR)=20
{
        print=20
"DIR";
       =20
exit;
        next if $file =
=3D~=20
/\*(b|x|l)$/;
        print =
"Putting=20
$file\n" if $debug;
        =
style=3D"BACKGROUND-COLOR: rgb(255,255,0)">ftp->put($file) or =
warn=20
"Failed '$file': $! ($^E)";
    =20
}
     closedir DIR;
 =20

    }
}

$ftp->close;
print =
"Transfering=20
ends\n";
exit=20
=
0;

#===================3D=3 D=3D=
==================== =====3D=
==================== =====3D=
=====3D
#         =
;            =
          =20
=
Subroutines
#===================3D=
==================== =====3D=
==================== =====3D=
=======3D

sub=20
fail {

$ftp->quit;
die "ftp error=20
occurred\n";

}


__END__

my $files =3D =
$ftp->dir()=20
or die "Error doing ftp->dir: $!\n";
my $files =3D dir() or =
die "Error=20
doing dir: $!\n";
foreach (@$files) {
    # =
skip=20
lines not starting with d or -
    if (/^[^d-]/) =

{
         print =
"Skipping=20
garbage dir line\n" if=20
$debug;
       =20
next;
    }

# ftp dir =
listing
#----0----- -1-=20
---2---- ---3---- ---4---- -5- -6 --7-- -----8--------
#total=20
52
#drwx--x---   3 owner   =20
group        1024 Dec 13  =
1997=20
.
#drwxr-xr-x 671 owner   =20
group       49152 Dec 18 14:09=20
..
#-rw-r--r--   1 xyz     =20
httpd        2010 Sep 21 13:31=20
index.htm

    my ($size, $file) =3D (split =
/\s+/, $_,=20
9)[4,8];    # get =
size/filename
    next=20
if $file =3D~ =
/^\.{1,2}$/;        # skip=20
. and ..

    # if directory - call directory =
recurse=20
routine

    if (/^d/)=20
{
       =20
...





------_=_NextPart_001_01CA88A6.D767EADA--


--===============1653116433==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1653116433==--

RE: help with ftp

am 29.12.2009 18:14:55 von zilore mumba

--===============1588562040==
Content-Type: multipart/alternative; boundary="0-562042941-1262106895=:17804"

--0-562042941-1262106895=:17804
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Jeff,
Thanks very much for the hint. With mkdir it actually created the directori=
es once but had a problem with put.=20
When I rerun it it fails again at mkdir. (incidentally I do not know what v=
alue to put in for RECURSE. when I type RECURSE it gives of a breword RECUR=
SE).
Thanks for sparing your time.
Zilore



--- On Tue, 12/29/09, Jeff Saxton wrote:

From: Jeff Saxton
Subject: RE: help with ftp
To: "zilore mumba" , "activeperl@listserv.activestate.com=
"
Date: Tuesday, December 29, 2009, 4:45 PM

=0A =0A from the pod:  =0Amkdir ( DIR [, RECURSE ]) Create a=
new directory with the name DIR. If RECURSE is=0Atrue then mkdir will atte=
mpt to create all the directories in the given path.     =0A=
=0AFrom: activeperl-bounces@listserv.ActiveState.com [activeperl-bounces@li=
stserv.ActiveState.com] On Behalf Of zilore mumba [zmumba@yahoo.com]
=0ASent: Tuesday, December 29, 2009 6:00 AM
=0ATo: activeperl@listserv.activestate.com
=0ASubject: help with ftp
=0A
=0AHello Perl Community.
=0AThanks so much for all the help provided lduring the current year.
=0AHappy and prosperous New Year 2010 to all.
=0A
=0ABelow is my code where I have a problem with ftp. I am trying to transfe=
r data from one PC to another. When I try to make a directory on the distan=
t machine, I get the error: "Can't locate object method 'mkpath' via packag=
e 'ftp".
=0AWhen I comment this part out, the same error appears later on with "ftp-=
>put".
=0ABoth parts with problem are highlighted in yellow.
=0A
=0AI am not able to find help in Perldoc.
=0AAny help will be appreciated
=0A
=0AZilore
=0A
=0A
=0A#!/usr/bin/perl -w
=0A#This transfers files from a=A0 PC running LINUX to Windows PC.
=0A#
=0Ause Net::FTP;
=0A
=0Ause strict;
=0Ause warnings;
=0Ause POSIX;
=0Ause File::Path;
=0Ause File::Copy;
=0A
=0Amy $debug =3D 1;
=0A# set variables
=0A#
=0Amy $User =3D 'pc-mis';
=0Amy $Pass =3D 'acmad11';
=0Amy $Host =3D '192.168.2.115';
=0A
=0Amy @models =3D ('arpege', 'ukmo', 'ecmf');
=0Amy @now =3D localtime;
=0Amy $dat =3D strftime "%Y%m%d", @now;
=0Amy $mon_ab =3D strftime "%b",@now;
=0Amy $mon_num =3D strftime "%m",@now;
=0Amy $mon_name =3D strftime "%B",@now;
=0Amy $yr=3Dstrftime "%y",@now;
=0A
=0Amy $dash=3D"-";
=0Amy $mod =3D "models";
=0A
=0Amy ($day, $month, $year) =3D (localtime(time() - 60 * 60 * 24)) [ 3, 4, =
5 ];
=0A$year =3D $year+1900;
=0A$month =3D $month+1;
=0A
=0Amy $dat0 =3D sprintf("%04d%02d%02d",=A0 $year, $month, $day );
=0A
=0Amy $archive_dir =3D "../ARCHIVE/$mon_num$dash$mon_name$yr";   # wher=
e data is
=0A
=0Amy $remote_basedir =3D '/';
=0Amy $data_dir =3D "ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mod"=
; #where to put it
=0A
=0Amy @localdir =3D("../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]/$dat0"=
,
             =A0 "../ARCHIVE/$mon_num$dash$mon=
_name$yr/$models[1]/$dat0",
      =A0   =A0    "../ARCHIVE/$mon_num$dash$mon_name$=
yr/$models[2]/$dat0");=20
=0A
=0A#my @remotedir =3D ('$data_dir/$models[0]/$dat0','$data_dir/$models[1]/$=
dat0',
=0A#                 '$data_dir/$models[2]/=
$dat0');
=0A
=0A# connect to the remote host
=0A
=0Aprint "Connecting to $Host ...\n";
=0Amy $ftp =3D Net::FTP->new($Host, Timeout =3D> 360, Passive =3D> 'true') =
or fail ();
   =20
=0A$ftp->login($User,$Pass) or die " login '$ftp'=A0 failed: $_ ($^E)";
=0A$ftp->binary;
=0A
=0Aforeach my $ddir (@remotedir) {
    if (! -d $ddir) {
        print "mkpath $ddir\n" if $debug;
        $ftp->mkpath ($ddir) or die "mkpath '$ddir' failed=
: $! ($^E)";
 =A0 }
=0A}
=0A$ftp->cwd($data_dir);
=0A
=0A# transfer data
=0A
=0Aprint "Transfering data\n";
=0A
=0A#my %numbers =3D ('$localdirs[0]' =3D> '0','localdirs[1]' =3D> '1','loca=
ldirs[2]' =3D> '2');
=0A
=0Amy %remotedirs =3D ();
=0Amy $remotedirs;
   =20
=0Aforeach my $model (@models) {
=0A
    # define local and remote directories before copying files
=0A
    if ($model eq 'arpege') {
   =A0 my $remotedirs =3D "$data_dir/$models[0]/$dat0";
       $remotedirs{$remotedirs} =3D $localdir[0];
=0A
  } elsif ($model eq 'ukmo') {
   =A0 my $remotedirs =3D "$data_dir/$models[1]/$dat0";
     =A0 $remotedirs{$remotedirs} =3D $localdir[1];
=0A
  } elsif ($model eq 'ecmf') {
   =A0 my $remotedirs =3D "$data_dir/$models[2]/$dat0";
     =A0 $remotedirs{$remotedirs} =3D $localdir[2];
  }
 =20
    # Transfer files
=0A
    foreach my $rdir (keys %remotedirs) {
    =A0$ftp->cwd($remotedirs($rdir));
=0A
   =A0 my $ldir =3D $remotedirs{$rdir}
    
    =A0print "Transfering files from $ldir to $remotedirs(rdir)\n"=
if $debug;
   =A0 opendir DIR, "$ldir" or die "opendir '$ldir: $! ($^E)";
   =A0 while (my $file =3D readdir DIR) {
        print "DIR";
        exit;
        next if $file =3D~ /\*(b|x|l)$/;
        print "Putting $file\n" if $debug;
        ftp->put($file) or warn "Failed '$file': $! ($^E)"=
;
   =A0 }
   =A0 closedir DIR;
 =20
    }
=0A}
=0A
=0A$ftp->close;
=0Aprint "Transfering ends\n";
=0Aexit 0;
=0A
=0A#===================3 D=====
==================== =====3D=
==================== =====3D=
===3D
=0A#                  =A 0    =
         Subroutines
=0A#===================3 D=====
==================== =====3D=
==================== =====3D=
===3D
=0A
=0Asub fail {
=0A
=0A$ftp->quit;
=0Adie "ftp error occurred\n";
=0A
=0A}
=0A
=0A
=0A__END__
=0A
=0Amy $files =3D $ftp->dir() or die "Error doing ftp->dir: $!\n";
=0Amy $files =3D dir() or die "Error doing dir: $!\n";
=0Aforeach (@$files) {
    # skip lines not starting with d or -
    if (/^[^d-]/) {
       =A0 print "Skipping garbage dir line\n" if $debug;
        next;
    }
=0A
=0A# ftp dir listing
=0A#----0----- -1- ---2---- ---3---- ---4---- -5- -6 --7-- -----8--------
=0A#total 52
=0A#drwx--x---   3 owner  =A0 group      =A0 1024 Dec 1=
3=A0 1997 .
=0A#drwxr-xr-x 671 owner  =A0 group       49152 Dec 18 14:0=
9 ..
=0A#-rw-r--r--   1 xyz    =A0 httpd      =A0 2010 S=
ep 21 13:31 index.htm
=0A
    my ($size, $file) =3D (split /\s+/, $_, 9)[4,8];  =A0 # ge=
t size/filename
    next if $file =3D~ /^\.{1,2}$/;      =A0 # skip . =
and ..
=0A
    # if directory - call directory recurse routine
=0A
    if (/^d/) {
        ...
=0A
=0A
=0A

--0-562042941-1262106895=:17804
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

=0A=0A valign=3D"top">Hello Perl Community.
=0AThanks so much for all the help=
provided lduring the current year.
=0AHappy and prosperous New Year 201=
0 to all.
=0A
=0ABelow is my code where I have a problem with ftp. I =
am trying to transfer data from one PC to another. When I try to make a dir=
ectory on the distant machine, I get the error: "Can't locate object method=
'mkpath' via package 'ftp".
=0AWhen I comment this part out, the same e=
rror appears later on with "ftp->put".
=0ABoth parts with problem are=
highlighted in yellow.
=0A
=0AI am not able to find help in Perldoc.=

=0AAny help will be appreciated
=0A
=0AZilore
=0A
=0A
=
=0A#!/usr/bin/perl -w
=0A#This transfers files from a  PC running L=
INUX to Windows PC.
=0A#
=0Ause Net::FTP;
=0A
=0Ause strict; >=0Ause warnings;
=0Ause POSIX;
=0Ause File::Path;
=0Ause File::Co=
py;
=0A
=0Amy $debug =3D 1;
=0A# set variables
=0A#
=0Amy $U=
ser =3D 'pc-mis';
=0Amy $Pass =3D 'acmad11';
=0Amy $Host =3D '192.168=
..2.115';
=0A
=0Amy @models =3D ('arpege', 'ukmo', 'ecmf');
=0Amy @=
now =3D localtime;
=0Amy $dat =3D strftime "%Y%m%d", @now;
=0Amy $mon=
_ab =3D strftime "%b",@now;
=0Amy $mon_num =3D strftime "%m",@now;
=
=0Amy $mon_name =3D strftime "%B",@now;
=0Amy $yr=3Dstrftime "%y",@now;<=
br>=0A
=0Amy $dash=3D"-";
=0Amy $mod =3D "models";
=0A
=0Amy ($=
day, $month, $year) =3D (localtime(time() - 60 * 60 * 24)) [ 3, 4, 5 ];
=
=0A$year =3D $year+1900;
=0A$month =3D $month+1;
=0A
=0Amy $dat0 =
=3D sprintf("%04d%02d%02d",  $year, $month, $day );
=0A
=0Amy $a=
rchive_dir =3D "../ARCHIVE/$mon_num$dash$mon_name$yr";   # where =
data is
=0A
=0Amy $remote_basedir =3D '/';
=0Amy $data_dir =3D "AR=
CHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mod"; #where to put it
=
=0A
=0Amy @localdir =3D("../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]=
/$dat0",
=0A          =
     "../ARCHIVE/$mon_num$dash$mon_name$yr/$models[1]/$=
dat0",
=0A             =
;  "../ARCHIVE/$mon_num$dash$mon_name$yr/$models[2]/$dat0");
=0A r>=0A#my @remotedir =3D ('$data_dir/$models[0]/$dat0','$data_dir/$models[1]=
/$dat0',
=0A#          =
;       '$data_dir/$models[2]/$dat0');
=0A=

=0A# connect to the remote host
=0A
=0Aprint "Connecting to $Host=
...\n";
=0Amy $ftp =3D Net::FTP->new($Host, Timeout =3D> 360, Pas=
sive =3D> 'true') or fail ();
=0A   
=0A$ftp->l=
ogin($User,$Pass) or die " login '$ftp'  failed: $_ ($^E)";
=0A$ftp=
->binary;
=0A
=0A ;">foreach my $ddir (@remotedir) {
(255, 255, 0);">=0A&nbs=
p;   if (! -d $ddir) {

55, 255, 0);">=0A =
       print "mkpath $ddir\n" if $debug; n>
=0A round-color: rgb(255, 255, 0);">        =
$ftp->mkpath ($ddir) or die "mkpath '$ddir' failed: $! ($^E)";
style=3D"background-color: rgb(255, 255, 0);">=0A -color: rgb(255, 255, 0);">   }
or: rgb(255, 255, 0);">=0A ;">}
=0A$ftp->cwd($data_dir);
=0A
=0A# transfer data
=
=0A
=0Aprint "Transfering data\n";
=0A
=0A#my %numbers =3D ('$loca=
ldirs[0]' =3D> '0','localdirs[1]' =3D> '1','localdirs[2]' =3D> '2'=
);
=0A
=0Amy %remotedirs =3D ();
=0Amy $remotedirs;
=0A &n=
bsp; 
=0Aforeach my $model (@models) {
=0A
=0A  &n=
bsp; # define local and remote directories before copying files
=0A
=
=0A    if ($model eq 'arpege') {
=0A   &nb=
sp; my $remotedirs =3D "$data_dir/$models[0]/$dat0";
=0A  &nbs=
p;    $remotedirs{$remotedirs} =3D $localdir[0];
=0A
=0A&nb=
sp; } elsif ($model eq 'ukmo') {
=0A     my $remoted=
irs =3D "$data_dir/$models[1]/$dat0";
=0A     &=
nbsp; $remotedirs{$remotedirs} =3D $localdir[1];
=0A
=0A  } elsi=
f ($model eq 'ecmf') {
=0A     my $remotedirs =3D "$=
data_dir/$models[2]/$dat0";
=0A       $rem=
otedirs{$remotedirs} =3D $localdir[2];
=0A  }
=0A 
=0A&=
nbsp;   # Transfer files
=0A
=0A    foreach =
my $rdir (keys %remotedirs) {
=0A     $ftp->cwd($=
remotedirs($rdir));
=0A
=0A     my $ldir =3D $rem=
otedirs{$rdir}
=0A    
=0A    &nb=
sp;print "Transfering files from $ldir to $remotedirs(rdir)\n" if $debug; r>=0A     opendir DIR, "$ldir" or die "opendir '$ldir: =
$! ($^E)";
=0A     while (my $file =3D readdir DIR) =
{
=0A        print "DIR";
=0A =
;       exit;
=0A    &=
nbsp;   next if $file =3D~ /\*(b|x|l)$/;
=0A   =
     print "Putting $file\n" if $debug;
=0A &nb=
sp;      255, 0);">ftp->put($file) or warn "Failed '$file': $! ($^E)"; >=0A     }
=0A     closedir DIR;=

=0A 
=0A    }
=0A}
=0A
=0A$ftp->clo=
se;
=0Aprint "Transfering ends\n";
=0Aexit 0;
=0A
=0A#===3D=
==================== =====3D=
==================== =====3D=
==================== ===3D
=
=0A#            =
;            &n=
bsp;       Subroutines
=0A#=====3D=
==================== =====3D=
==================== =====3D=
==================== =3D
=0A
=
=0Asub fail {
=0A
=0A$ftp->quit;
=0Adie "ftp error occurred\n";=

=0A
=0A}
=0A
=0A
=0A__END__
=0A
=0Amy $files =3D $ftp=
->dir() or die "Error doing ftp->dir: $!\n";
=0Amy $files =3D dir(=
) or die "Error doing dir: $!\n";
=0Aforeach (@$files) {
=0A &nb=
sp;  # skip lines not starting with d or -
=0A    if=
(/^[^d-]/) {
=0A         print =
"Skipping garbage dir line\n" if $debug;
=0A    &nbs=
p;   next;
=0A    }
=0A
=0A# ftp dir list=
ing
=0A#----0----- -1- ---2---- ---3---- ---4---- -5- -6 --7-- -----8---=
-----
=0A#total 52
=0A#drwx--x---   3 owner  &nbs=
p; group        1024 Dec 13  1997 .=

=0A#drwxr-xr-x 671 owner    group    =
;   49152 Dec 18 14:09 ..
=0A#-rw-r--r--   1 xyz&nbs=
p;     httpd        =
2010 Sep 21 13:31 index.htm
=0A
=0A    my ($size, $fil=
e) =3D (split /\s+/, $_, 9)[4,8];    # get size/filename
=
=0A    next if $file =3D~ /^\.{1,2}$/;   &nbs=
p;    # skip . and ..
=0A
=0A    # if d=
irectory - call directory recurse routine
=0A
=0A    i=
f (/^d/) {
=0A        ...
=0A
=
=0A
=0A=0A
=0A=0A
top" style=3D"font: inherit;">Jeff,
Thanks very much for the hint. With =
mkdir it actually created the directories once but had a problem with put. =

When I rerun it it fails again at mkdir. (incidentally I do not know wh=
at value to put in for RECURSE. when I type RECURSE it gives of a breword R=
ECURSE).
Thanks for sparing your time.
Zilore



--- On <=
b>Tue, 12/29/09, Jeff Saxton <jeff_saxton@bigfix.com> wrot=
e:
left: 5px; padding-left: 5px;">
From: Jeff Saxton <jeff_saxton@bigfix=
..com>
Subject: RE: help with ftp
To: "zilore mumba" <zmumba@yah=
oo.com>, "activeperl@listserv.activestate.com" <activeperl@listserv.a=
ctivestate.com>
Date: Tuesday, December 29, 2009, 4:45 PM

id=3D"yiv959726055">=0A =0A =0A=0A
000" face=3D"Tahoma" size=3D"2">from the pod:
=0A
r"> 
=0A
=
=0A
=0A

Crea=
te a new directory with the name DIR. If RECURSE =
is=0Atrue then mkdir will attempt to create all the dir=
ectories in the given path.

=0A
=0A

=3D"times new roman"> 

=0A

 

=0A
d=3D"divRpF981374" style=3D"direction: ltr;">=0A
=0A t face=3D"Tahoma" size=3D"2">From: activeperl-bounces@listserv.Activ=
eState.com [activeperl-bounces@listserv.ActiveState.com] On Behalf Of zilor=
e mumba [zmumba@yahoo.com]
=0ASent: Tuesday, December 29, 2009 6:=
00 AM
=0ATo: activeperl@listserv.activestate.com
=0ASubject=
:
help with ftp
=0A
=0A
=0A
=0A
=0A le border=3D"0" cellpadding=3D"0" cellspacing=3D"0">=0A
=0A
=0A=0A =0A<=
/blockquote>

--0-562042941-1262106895=:17804--

--===============1588562040==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1588562040==--

RE: help with ftp

am 29.12.2009 18:19:24 von Jeff Saxton

--===============1550139607==
Content-Language: en-US
Content-Type: multipart/alternative;
boundary="_000_6DFE695E783E004A9E6D2CD1E0B8CA1F0BEF0A1302bma il2bigfixc_"

--_000_6DFE695E783E004A9E6D2CD1E0B8CA1F0BEF0A1302bmail2bigfi xc_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Recurse is probably a Boolean i.e. 0|1

Your put is failing because you're doing ftp->put not $ftp->put


________________________________
From: zilore mumba [mailto:zmumba@yahoo.com]
Sent: Tuesday, December 29, 2009 9:15 AM
To: activeperl@listserv.activestate.com; Jeff Saxton
Subject: RE: help with ftp

Jeff,
Thanks very much for the hint. With mkdir it actually created the directori=
es once but had a problem with put.
When I rerun it it fails again at mkdir. (incidentally I do not know what v=
alue to put in for RECURSE. when I type RECURSE it gives of a breword RECUR=
SE).
Thanks for sparing your time.
Zilore



--- On Tue, 12/29/09, Jeff Saxton wrote:

From: Jeff Saxton
Subject: RE: help with ftp
To: "zilore mumba" , "activeperl@listserv.activestate.com=
"
Date: Tuesday, December 29, 2009, 4:45 PM
from the pod:

mkdir ( DIR [, RECURSE ])

Create a new directory with the name DIR. If RECURSE is true then mkdir wil=
l attempt to create all the directories in the given path.





________________________________
From: activeperl-bounces@listserv.ActiveState.com [activeperl-bounces@lists=
erv.ActiveState.com] On Behalf Of zilore mumba [zmumba@yahoo.com]
Sent: Tuesday, December 29, 2009 6:00 AM
To: activeperl@listserv.activestate.com
Subject: help with ftp
Hello Perl Community.
Thanks so much for all the help provided lduring the current year.
Happy and prosperous New Year 2010 to all.

Below is my code where I have a problem with ftp. I am trying to transfer d=
ata from one PC to another. When I try to make a directory on the distant m=
achine, I get the error: "Can't locate object method 'mkpath' via package '=
ftp".
When I comment this part out, the same error appears later on with "ftp->pu=
t".
Both parts with problem are highlighted in yellow.

I am not able to find help in Perldoc.
Any help will be appreciated

Zilore


#!/usr/bin/perl -w
#This transfers files from a PC running LINUX to Windows PC.
#
use Net::FTP;

use strict;
use warnings;
use POSIX;
use File::Path;
use File::Copy;

my $debug =3D 1;
# set variables
#
my $User =3D 'pc-mis';
my $Pass =3D 'acmad11';
my $Host =3D '192.168.2.115';

my @models =3D ('arpege', 'ukmo', 'ecmf');
my @now =3D localtime;
my $dat =3D strftime "%Y%m%d", @now;
my $mon_ab =3D strftime "%b",@now;
my $mon_num =3D strftime "%m",@now;
my $mon_name =3D strftime "%B",@now;
my $yr=3Dstrftime "%y",@now;

my $dash=3D"-";
my $mod =3D "models";

my ($day, $month, $year) =3D (localtime(time() - 60 * 60 * 24)) [ 3, 4, 5 ]=
;
$year =3D $year+1900;
$month =3D $month+1;

my $dat0 =3D sprintf("%04d%02d%02d", $year, $month, $day );

my $archive_dir =3D "../ARCHIVE/$mon_num$dash$mon_name$yr"; # where data =
is

my $remote_basedir =3D '/';
my $data_dir =3D "ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mod"; #=
where to put it

my @localdir =3D("../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]/$dat0",
"../ARCHIVE/$mon_num$dash$mon_name$yr/$models[1]/$dat0",
"../ARCHIVE/$mon_num$dash$mon_name$yr/$models[2]/$dat0");

#my @remotedir =3D ('$data_dir/$models[0]/$dat0','$data_dir/$models[1]/$dat=
0',
# '$data_dir/$models[2]/$dat0');

# connect to the remote host

print "Connecting to $Host ...\n";
my $ftp =3D Net::FTP->new($Host, Timeout =3D> 360, Passive =3D> 'true') or =
fail ();

$ftp->login($User,$Pass) or die " login '$ftp' failed: $_ ($^E)";
$ftp->binary;

foreach my $ddir (@remotedir) {
if (! -d $ddir) {
print "mkpath $ddir\n" if $debug;
$ftp->mkpath ($ddir) or die "mkpath '$ddir' failed: $! ($^E)";
}
}
$ftp->cwd($data_dir);

# transfer data

print "Transfering data\n";

#my %numbers =3D ('$localdirs[0]' =3D> '0','localdirs[1]' =3D> '1','localdi=
rs[2]' =3D> '2');

my %remotedirs =3D ();
my $remotedirs;

foreach my $model (@models) {

# define local and remote directories before copying files

if ($model eq 'arpege') {
my $remotedirs =3D "$data_dir/$models[0]/$dat0";
$remotedirs{$remotedirs} =3D $localdir[0];

} elsif ($model eq 'ukmo') {
my $remotedirs =3D "$data_dir/$models[1]/$dat0";
$remotedirs{$remotedirs} =3D $localdir[1];

} elsif ($model eq 'ecmf') {
my $remotedirs =3D "$data_dir/$models[2]/$dat0";
$remotedirs{$remotedirs} =3D $localdir[2];
}

# Transfer files

foreach my $rdir (keys %remotedirs) {
$ftp->cwd($remotedirs($rdir));

my $ldir =3D $remotedirs{$rdir}

print "Transfering files from $ldir to $remotedirs(rdir)\n" if $debug;
opendir DIR, "$ldir" or die "opendir '$ldir: $! ($^E)";
while (my $file =3D readdir DIR) {
print "DIR";
exit;
next if $file =3D~ /\*(b|x|l)$/;
print "Putting $file\n" if $debug;
ftp->put($file) or warn "Failed '$file': $! ($^E)";
}
closedir DIR;

}
}

$ftp->close;
print "Transfering ends\n";
exit 0;

#===================3D=3 D=====
==================== =====3D=
==================== =====3D=
==
# Subroutines
#===================3D=3 D=====
==================== =====3D=
==================== =====3D=
==

sub fail {

$ftp->quit;
die "ftp error occurred\n";

}


__END__

my $files =3D $ftp->dir() or die "Error doing ftp->dir: $!\n";
my $files =3D dir() or die "Error doing dir: $!\n";
foreach (@$files) {
# skip lines not starting with d or -
if (/^[^d-]/) {
print "Skipping garbage dir line\n" if $debug;
next;
}

# ftp dir listing
#----0----- -1- ---2---- ---3---- ---4---- -5- -6 --7-- -----8--------
#total 52
#drwx--x--- 3 owner group 1024 Dec 13 1997 .
#drwxr-xr-x 671 owner group 49152 Dec 18 14:09 ..
#-rw-r--r-- 1 xyz httpd 2010 Sep 21 13:31 index.htm

my ($size, $file) =3D (split /\s+/, $_, 9)[4,8]; # get size/filename
next if $file =3D~ /^\.{1,2}$/; # skip . and ..

# if directory - call directory recurse routine

if (/^d/) {
...





--_000_6DFE695E783E004A9E6D2CD1E0B8CA1F0BEF0A1302bmail2bigfi xc_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:st1=3D"urn:schemas-microsoft-com:office:smarttags" xmlns=3D"http://ww=
w.w3.org/TR/REC-html40">


>

namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags" name=3D"Person=
Name"/>









=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Recurse is probably a Boolean i.e. 0|1=



=3D'font-size:
10.0pt;font-family:Arial;color:navy'> 



=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Your put is failing because you’=
re
doing ftp->put not $ftp->put



=3D'font-size:
10.0pt;font-family:Arial;color:navy'> 



=3D'font-size:
10.0pt;font-family:Arial;color:navy'> 





e=3D3
face=3D"Times New Roman">






ze:10.0pt;
font-family:Tahoma;font-weight:bold'>From:
face=3DTahoma> zilore m=
umba
[mailto:zmumba@yahoo.com]

Sent: Tuesday, December 29, =
2009
9:15 AM

To:
activeperl@listserv.activestate.com; Jeff Saxto=
n


Subject: RE: help with ftp span>





'font-size:
12.0pt'> 








style=3D'font-size:12.0pt'>Jeff,

Thanks very much for the hint. With mkdir it actually created the directo=
ries
once but had a problem with put.

When I rerun it it fails again at mkdir. (incidentally I do not know what
value to put in for RECURSE. when I type RECURSE it gives of a breword
RECURSE).

Thanks for sparing your time.

Zilore







--- On Tue, 12/29/09, w:st=3D"on">Jeff Saxton lic'><jeff_saxton@bigfix.com>
wrote:


face=3D"Times New Roman">

From: Jeff Saxton
<jeff_saxton@bigfix.com>

Subject: RE: help with ftp

To: "zilore mumba" <zmumba@yahoo.com>,
"activeperl@listserv.activestate.com"
<activeperl@listserv.activestate.com>

Date: Tuesday, December 29, 2009, 4:45 PM




style=3D'font-size:10.0pt;font-family:Tahoma;color:black'>fr om the pod: span>




style=3D'font-size:12.0pt'> 




style=3D'font-size:12.0pt'>mkdir ( DIR [, RECURSE ]) font>


an
style=3D'font-size:12.0pt'>Create a new directory with the name font> size=3D2 face=3D"Courier New">DIR=
.
If 0pt'>RECURSE
is true then size=3D2 face=3D"Courier New">mkdir n>

will attempt to create all the directories in the given path.<=
/p>


t'> 


t'> 



ize=3D3
face=3D"Times New Roman">



e=3DTahoma> style=3D'font-size:10.0pt;font-family:Tahoma;font-weight:bol d'>From: n> size=3D2 face=3DTahoma> '>
activeperl-bounces@listserv.ActiveState.com
[activeperl-bounces@listserv.ActiveState.com] On Behalf Of zilore mumba
[zmumba@yahoo.com]

Sent: Tuesday, December 29=
, 2009
6:00 AM

To: activeperl@listserv.ac=
tivestate.com

Subject: help with ftp an>









face=3D"Times New Roman">Hello Perl Co=
mmunity.

Thanks so much for all the help provided lduring the current year.

Happy and prosperous New Year 2010 to all.



Below is my code where I have a problem with ftp. I am trying to transf=
er
data from one PC to another. When I try to make a directory on the dist=
ant
machine, I get the error: "Can't locate object method 'mkpath' via
package 'ftp".

When I comment this part out, the same error appears later on with
"ftp->put".

Both parts with problem are highlighted in yellow.



I am not able to find help in Perldoc.

Any help will be appreciated



Zilore





#!/usr/bin/perl -w

#This transfers files from a  PC running LINUX to Windows PC.

#

use Net::FTP;



use strict;

use warnings;

use POSIX;

use File::Path;

use File::Copy;



my $debug =3D 1;

# set variables

#

my $User =3D 'pc-mis';

my $Pass =3D 'acmad11';

my $Host =3D '192.168.2.115';



my @models =3D ('arpege', 'ukmo', 'ecmf');

my @now =3D localtime;

my $dat =3D strftime "%Y%m%d", @now;

my $mon_ab =3D strftime "%b",@now;

my $mon_num =3D strftime "%m",@now;

my $mon_name =3D strftime "%B",@now;

my $yr=3Dstrftime "%y",@now;



my $dash=3D"-";

my $mod =3D "models";



my ($day, $month, $year) =3D (localtime(time() - 60 * 60 * 24)) [ 3, 4,=
5 ];

$year =3D $year+1900;

$month =3D $month+1;



my $dat0 =3D sprintf("%04d%02d%02d",  $year, $month, $da=
y );



my $archive_dir =3D
"../ARCHIVE/$mon_num$dash$mon_name$yr";   # where d=
ata
is



my $remote_basedir =3D '/';

my $data_dir =3D
"ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mod"; #whe=
re
to put it



my @localdir
=3D("../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]/$dat0",<=
br>
            =
;  
"../ARCHIVE/$mon_num$dash$mon_name$yr/$models[1]/$dat0",

              
"../ARCHIVE/$mon_num$dash$mon_name$yr/$models[2]/$dat0"); >


#my @remotedir =3D ('$data_dir/$models[0]/$dat0','$data_dir/$models[1]/=
$dat0',

#           &nbs=
p;    
'$data_dir/$models[2]/$dat0');



# connect to the remote host



print "Connecting to $Host ...\n";

my $ftp =3D Net::FTP->new($Host, Timeout =3D> 360, Passive =3D>=
; 'true')
or fail ();

   

$ftp->login($User,$Pass) or die " login '$ftp'  failed: $_
($^E)";

$ftp->binary;



foreach my $ddir (@remotedir) { >

    if (! -d $ddir) {<=
/span>

      &=
nbsp;
print "mkpath $ddir\n" if $debug;


      &=
nbsp;
$ftp->mkpath ($ddir) or die "mkpath '$ddir' failed: $! ($^E)&qu=
ot;;


   }

}

$ftp->cwd($data_dir);



# transfer data



print "Transfering data\n";



#my %numbers =3D ('$localdirs[0]' =3D> '0','localdirs[1]' =3D>
'1','localdirs[2]' =3D> '2');



my %remotedirs =3D ();

my $remotedirs;

   

foreach my $model (@models) {



    # define local and remote directories before copying
files



    if ($model eq 'arpege') {

     my $remotedirs =3D
"$data_dir/$models[0]/$dat0";

       $remotedirs{$remotedirs} =3D $localdir[=
0];



  } elsif ($model eq 'ukmo') {

     my $remotedirs =3D
"$data_dir/$models[1]/$dat0";

       $remotedirs{$remotedirs} =3D
$localdir[1];



  } elsif ($model eq 'ecmf') {

     my $remotedirs =3D
"$data_dir/$models[2]/$dat0";

       $remotedirs{$remotedirs} =3D
$localdir[2];

  }

 

    # Transfer files



    foreach my $rdir (keys %remotedirs) {

     $ftp->cwd($remotedirs($rdir));



     my $ldir =3D $remotedirs{$rdir}

    

     print "Transfering files from $ldir to
$remotedirs(rdir)\n" if $debug;

     opendir DIR, "$ldir" or die
"opendir '$ldir: $! ($^E)";

     while (my $file =3D readdir DIR) {

        print "DIR";

        exit;

        next if $file =3D~ /\*(b|x|l=
)$/;

        print "Putting
$file\n" if $debug;

        llow'>ftp->put($file)
or warn "Failed '$file': $! ($^E)";


     }

     closedir DIR;

 

    }

}



$ftp->close;

print "Transfering ends\n";

exit 0;



#===================3D=3 D===3D=
==================== =====3D=
==================== =====3D=
===3D

#           &nbs=
p;            &=
nbsp;      
Subroutines

#===================3D=3 D===3D=
==================== =====3D=
==================== =====3D=
===3D



sub fail {



$ftp->quit;

die "ftp error occurred\n";



}





__END__



my $files =3D $ftp->dir() or die "Error doing ftp->dir:
$!\n";

my $files =3D dir() or die "Error doing dir: $!\n";

foreach (@$files) {

    # skip lines not starting with d or -

    if (/^[^d-]/) {

         print "Skipping
garbage dir line\n" if $debug;

        next;

    }



# ftp dir listing

#----0----- -1- ---2---- ---3---- ---4---- -5- -6 --7-- -----8--------<=
br>
#total 52

#drwx--x---   3 owner   
group        1024 Dec 13  1997 =
..

#drwxr-xr-x 671 owner   
group       49152 Dec 18 14:09 ..

#-rw-r--r--   1 xyz     
httpd        2010 Sep 21 13:31 index=
..htm



    my ($size, $file) =3D (split /\s+/, $_,
9)[4,8];    # get size/filename

    next if $file =3D~
/^\.{1,2}$/;        # skip . and ..<=
br>


    # if directory - call directory recurse routine



    if (/^d/) {

        ...





style=3D'font-size:12.0pt'>






'font-size:
12.0pt'> 









--_000_6DFE695E783E004A9E6D2CD1E0B8CA1F0BEF0A1302bmail2bigfi xc_--

--===============1550139607==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1550139607==--

Re: help with ftp

am 30.12.2009 11:23:54 von zilore mumba

--===============1641112502==
Content-Type: multipart/alternative; boundary="0-265205198-1262168634=:52161"

--0-265205198-1262168634=:52161
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Bill,
Once again thanks very much for your very comprehensive script. It will all=
ow me to learn a lot of perl also. As it is quite long, it will take me tim=
e to digest. I will let you know when it works.
Incidentally do I insert the whole code (minus the notes at the end of cour=
se -very useful notes) and remove all my code after definition of the direc=
tories below?

My appreciation for your time.
Zilore



--- On Wed, 12/30/09, Bill Luebkert wrote:

From: Bill Luebkert
Subject: Re: help with ftp
To: "zilore mumba"
Date: Wednesday, December 30, 2009, 2:09 AM


  =A0 my $data_dir =3D "ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$da=
sh$mod";

  =A0 my @localdir =3D ( # looks like you have to run from dir parallel=
to ARCHIVE dir
  =A0 =A0 "../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]/$dat0",
  =A0 =A0 "../ARCHIVE/$mon_num$dash$mon_name$yr/$models[1]/$dat0",
  =A0 =A0 "../ARCHIVE/$mon_num$dash$mon_name$yr/$models[2]/$dat0",
  =A0 =A0   =A0 # would make more sense as /$yr$mon_num/ in the mid=
dle
  =A0 );


Script (putall.pl) - cut and paste into putall.pl (or whatever):
Nope that helps some.



=0A
--0-265205198-1262168634=:52161
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

top" style=3D"font: inherit;">Bill,
Once again thanks very much for your=
very comprehensive script. It will allow me to learn a lot of perl also. A=
s it is quite long, it will take me time to digest. I will let you know whe=
n it works.
Incidentally do I insert the whole code (minus the notes at =
the end of course -very useful notes) and remove all my code after definiti=
on of the directories below?

My appreciation for your time.
Zilor=
e



--- On Wed, 12/30/09, Bill Luebkert <dbecoll@road=
runner.com>
wrote:
d rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">
From: Bill Lu=
ebkert <dbecoll@roadrunner.com>
Subject: Re: help with ftp
To: =
"zilore mumba" <zmumba@yahoo.com>
Date: Wednesday, December 30, 20=
09, 2:09 AM


    my $data=
_dir =3D
"ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mod";

 &nbs=
p;  my @localdir =3D ( # looks like you have to run from dir parallel =
to ARCHIVE dir
      "../ARCHIVE/$mon_num$dash$mon_n=
ame$yr/$models[0]/$dat0",
      "../ARCHIVE/$mon_num=
$dash$mon_name$yr/$models[1]/$dat0",
      "../ARCHI=
VE/$mon_num$dash$mon_name$yr/$models[2]/$dat0",
     =
;     # would make more sense as /$yr$mon_num/ in the middle=

    );


Script (putall.pl) - cut and paste int=
o putall.pl (or whatever):
Nope that helps some.



blockquote>


--0-265205198-1262168634=:52161--

--===============1641112502==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1641112502==--

Re: help with ftp

am 30.12.2009 17:56:09 von zilore mumba

--===============0087656248==
Content-Type: multipart/alternative; boundary="0-1303611429-1262192169=:81485"

--0-1303611429-1262192169=:81485
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Bill,
Once again thanks very much for your very comprehensive script. It will all=
ow me to learn a lot of perl also. As it is quite long, it will take me tim=
e to digest. I will let you know when it works.
Incidentally do I insert the whole code (minus the notes at the end of cour=
se -very useful notes) and remove all my code after definition of the direc=
tories below?

My appreciation for your time.
Zilore



--- On Wed, 12/30/09, Bill Luebkert wrote:

From: Bill Luebkert
Subject: Re: help with ftp
To: "zilore mumba"
Date: Wednesday, December 30, 2009, 2:09 AM


  =A0 my $data_dir =3D "ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$da=
sh$mod";

  =A0 my @localdir =3D ( # looks like you have to run from dir parallel=
to ARCHIVE dir
  =A0 =A0 "../ARCHIVE/$mon_num$dash$mon_name$yr/$models[0]/$dat0",
  =A0 =A0 "../ARCHIVE/$mon_num$dash$mon_name$yr/$models[1]/$dat0",
  =A0 =A0 "../ARCHIVE/$mon_num$dash$mon_name$yr/$models[2]/$dat0",
  =A0 =A0   =A0 # would make more sense as /$yr$mon_num/ in the mid=
dle
  =A0 );


Script (putall.pl) - cut and paste into putall.pl (or whatever):
Nope that helps some.



=0A
--0-1303611429-1262192169=:81485
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

top" style=3D"font: inherit;">Bill,
Once again thanks very much for your=
very comprehensive script. It will allow me to learn a lot of perl also. A=
s it is quite long, it will take me time to digest. I will let you know whe=
n it works.
Incidentally do I insert the whole code (minus the notes at =
the end of course -very useful notes) and remove all my code after definiti=
on of the directories below?

My appreciation for your time.
Zilor=
e



--- On Wed, 12/30/09, Bill Luebkert <dbecoll@road=
runner.com>
wrote:
d rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">
From: Bill Lu=
ebkert <dbecoll@roadrunner.com>
Subject: Re: help with ftp
To: =
"zilore mumba" <zmumba@yahoo.com>
Date: Wednesday, December 30, 20=
09, 2:09 AM


    my $data=
_dir =3D
"ARCHIVE/$mon_num$dash$mon_name$yr/$mon_ab$yr$dash$mod";

 &nbs=
p;  my @localdir =3D ( # looks like you have to run from dir parallel =
to ARCHIVE dir
      "../ARCHIVE/$mon_num$dash$mon_n=
ame$yr/$models[0]/$dat0",
      "../ARCHIVE/$mon_num=
$dash$mon_name$yr/$models[1]/$dat0",
      "../ARCHI=
VE/$mon_num$dash$mon_name$yr/$models[2]/$dat0",
     =
;     # would make more sense as /$yr$mon_num/ in the middle=

    );


Script (putall.pl) - cut and paste int=
o putall.pl (or whatever):
Nope that helps some.



blockquote>


--0-1303611429-1262192169=:81485--

--===============0087656248==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0087656248==--