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

Is there a way to see if a file exists and is not a directory, ala  -f $fname, via a Net::SFTP connection?
Is there something more elegant than trying to open it and seeing if the open doesn't fail?
Thanks for any help

water

"Water, taken in moderation, cannot hurt anybody." -- Mark Twain

Replies are listed 'Best First'.
Re: -f over Net::SFTP
by PodMaster (Abbot) on May 27, 2004 at 02:55 UTC
    What does the documentation say? Have you tried doing a ls and comparing the output?

    Having read the documentation, I see there is no documented way of discerning a file from a directory (and I don't know how it's done via SFTP). One reasonable way of guessing is by examing the size attribute. On my server, directories are always listed as 4096 bytes in size. I'm guessing the flags and mode ought to be more revealing, but I don't have Net::SFTP installed to try so I can't say for sure.

    update: I think this ought to do it (its worth a try)

    ... use Fcntl ':mode'; my $a = $sftp->do_stat($path); warn "$path is a directory " if S_ISDIR($a->perm);

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.