Hi ,all :

       I have a trouble about the how to recur  list the ftp lists with the
perl .

The result like this :
---------------------------------------------------
/dir1
    /sub-dir1
     test1

/dir2
   /sub-dir2
                 test2

/dir3

  /sub-dir3
              test3
...
---------------------------------------------------

The following is my script :
---------------------------------------------------------------------------

   1. #!/usr/bin/perl
   2.
   3. use strict;
   4. use Net::FTP;
   5.
   6. my $host = "xxx.xxx.xx.xx";
   7. my $user = "test";
   8. my $pass = "xxx";
   9.
   10. print "Connecting to FTP Server ..."
   11.
   12. my $ftp = Net::FTP->new($host)
   13.              or die "Cannot connect the ftp server";
   14.
   15. $ftp->login ("$user", "$pass")
   16.                 or die "Cannot login" , $ftp->message;
   17.
   18. print "Logged in ...";
   19.
   20. $ftp->cwd ("/");
   21.
   22. my @dirs = $ftp->ls ('-l');
   23.
   24. sub if _a_dir {
   25.
   26.    my $dir = $_[0];
   27.        if ($dir  =~ m/^d/){
   28.         $ftp->cwd("$dir") or die "Error"
   29.                ..... (This  location is my problem )
   30. }
   31.
   32. foreach my $sub_dir (@dirs){
   33. &if_a_dir ($sub_dir);
   34. }
   35. $ftp->quit();

I don't know how to recursive list ftp files successfully.

Could someone can give me some suggestions?

Thanks in advance ...

Reply via email to