zalezny has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, on the beginning warm welcome to every one. Since few hours I`m trying to use Net::FTP::Recursive to list recursively all files on the some FTP server. At the moment its not possible for me because for some reason filehandler doesnt work for rls method. Maybe somebody will be able to help me here and solve my issue.
#!/home/tom/scripting/perl5/bin/perl use Net::FTP::Recursive; use warnings; use strict; use FileHandle; my $ftp = Net::FTP::Recursive->new("artfiles.org", Debug => 1); $ftp->login("anonymous",'me@here.there'); $ftp->cwd('/'); open FH,"> rlist.db"; my @ftpfiles; @ftpfiles = $ftp->rls(<FH>); print @ftpfiles; $ftp->quit;
I would like to be able to print output from $ftp->rls to screen and if its possible save it to file. It seems that I dont understand perl "filehandle". Maybe somebody will be able to help me here pasting working solution. FTP server is public(Centos mirror). How to list all files with using "rls" command on that server ? Thanks in advance for Your support. Zalezny

Replies are listed 'Best First'.
Re: Net::FTP::Recursive - how to use rls
by GotToBTru (Prior) on Oct 20, 2014 at 19:43 UTC

    The filehandle is what the open command creates, FH in your case. I suggest two things to try: (a) remove the <> around FH, and (b) include the parameter name.

    $ftp->rls(FH) or die $ftp->message; $ftp->rls(Filehandle=>FH) or die $ftp->message;
    1 Peter 4:10
      welcome zalezny, to add more words to what GotToBTru already said, consider that, for example: while (<FH>)
      is a shortcut to:
      while (defined ($_ = readline (*FH)))
      See more details on docs on IO operators.

      HtH
      L*
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Net::FTP::Recursive - how to use rls
by Loops (Curate) on Oct 20, 2014 at 20:08 UTC

    You can use File::Tee to capture standard output to a file as well as letting it go to the screen. Also, you need to pass the filehandle to rls with a Filehandle hash key:

    use strict; use warnings; use Net::FTP::Recursive; use File::Tee qw(tee); tee(*STDOUT, '>', 'capture.txt'); my $ftp = Net::FTP::Recursive->new("ftp.mozilla.org", Debug => 0); $ftp->login("anonymous",'me@here.there'); $ftp->rls( Filehandle => *STDOUT); $ftp->quit;
      Thank You very much for Your fast support! Its working like a charm. GoToBurn - thanks also for Your suggestions. This forum is increadably fast !