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

Hi all,

How to find the specified arg is dir or file? If it’s the local host we can use the test operation using –d or –f .Any efficient way to find the remote host’s file / files / dir ?

For example if I give abc:/home/user1/files , the script is able to know the given one is a file or directory and returns the code.

Something like to identify the below args
-----------------------------------------
abc:/home/user1/files
abc:/home/user1/dir
abc:/home/user1/files*

If not exists the args , return some error code or whatever.

thanks,
swaroop

Replies are listed 'Best First'.
Re: Remote file/files/dir ?
by blazar (Canon) on Oct 21, 2005 at 08:19 UTC
    Net::SFTP has the
    $sftp->do_lstat($path) $sftp->do_fstat($handle) $sftp->do_stat($path)
    methods. There may be other solutions/modules, but I'm quite confident these would work for you...
Re: Remote file/files/dir ?
by svenXY (Deacon) on Oct 21, 2005 at 08:35 UTC
    Hi,
    there is a File::Remote module. It does not offer a stat function or the -d ... operators, but might at least give you some kind of access to the file system on the other box. You could try to open() the remote entity - if you can, it's a file, otherwise you will at least get an error message that you might be able to catch and proceed accordingly.

    Update: In contrary to Net::SFTP, File::Remote uses ssh or rsh which is usually available whereas ++blazar's solution would require an SFTP server to connect to.
    On the other hand, his solution already provides functions for the test you require.
    Regards,
    svenXY