On Aug 24, 2:57 pm, [EMAIL PROTECTED] (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;



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to