in reply to Re: Net::SSH2::SFTP stat function
in thread Net::SSH2::SFTP stat function

Thanks for the suggestion! I did as you suggested:

use Fcntl ':mode'; my $mode = ...; if (S_ISDIR($mode)) { # directory ... }

But still no joy. It simply doesn't enter the "if" block, even though I'm doing a stat on a directory. I suspect it's got something to do with the fact that the files (and dirs) are on a remote host. Anyway, reading the docs on the builtin stat has shown me how to get the permissions, i.e.

my $ssh2 = Net::SSH2->new(); my $sftp = $ssh2->sftp(); my %fstat = $sftp->stat("${testdir}"); my $perm = $fstat{"mode"} & 07777;

But is there no way to get the file type in the same way, i.e. using an & operator on the mode?

Many thanks..

Replies are listed 'Best First'.
Re^3: Net::SSH2::SFTP stat function
by salva (Canon) on Oct 02, 2008 at 12:47 UTC
    yes, the S_IF* constants from Fcntl tell you the meaning of the remaining bits:
    S_IFREG => 32768 S_IFDIR => 16384 S_IFLNK => 40960 S_IFBLK => 24576 S_IFCHR => 8192 S_IFIFO => 4096 S_IFSOCK => 49152
    Regarding the compatibility of the different SSH/SFTP modules availables, read this post: Re^3: package that can handle ftp, sftp, http etc ?.
      Thanks, using the S_IF* constants works fine!