For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2007 > Re: Get names of files ONLY using module Net::SFTP::Foreign









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Get names of files ONLY using module Net::SFTP::Foreign
Salva

2007-08-27, 8:47 am

On Aug 24, 2:57 pm, bed...@nbs.sk (Marian Bednar) wrote:
> Hi all,
>
> I am a newbie in this forum and Perl too ;-)
>
> I am trying writing script transfering files using module
> Net::SFTP::Foreign.
>
> I need to retrieve from remote directory only names of files (not
> directories, links,etc.).
>


The permission flags for the remote object are available on the
Attributes object on the 'a' slot

You can use the S_IS* functions from Fcntl to check whether those flag
are for a particular kind of object, for instance S_ISREG for files
(similar to -f):

Also, the ls method from Net::SFTP::Foreign allows you to read all the
directory entries in one go, without requiring you to open the dir and
looping with readdir:

use strict;
use warnings;
use Net::SFTP::Foreign;
use Fcntl ':mode';

my $remote_dir = "/tmp";
my $sftp = Net::SFTP::Foreign->new("host");
$sftp->error and print "SSH connection failed: " . $sftp->error .
"\n";

my @files = $sftp->ls($remote_dir,
wanted => sub { S_ISREG($_[1]->{a}-
>perm) });


print "$_->{filename}\n" for @files;


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com