Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: In Perl, how to check for the remote folder existence using sftp command? Cant use Net:SFTP

by haukex (Archbishop)
on May 25, 2016 at 14:53 UTC ( [id://1164081]=note: print w/replies, xml ) Need Help??


in reply to In Perl, how to check for the remote folder existence using sftp command? Cant use Net:SFTP

Hi Yedu,

At least on my system, the "Couldn't canonicalise: ..." message gets printed to sftp's stderr stream, which the backticks you're using to run the command don't capture, and the sftp command itself exits normally after the "bye", which is why you're not seeing an error in $?.

My suggestion would be to switch to a module that is capable of capturing stderr when running the external command. My personal favorites are IPC::Run3 and Capture::Tiny. There's also the core module IPC::Cmd, which I don't have experience with.

The "not so nice" solution is to have the shell merge the command's stdout and stderr streams by inserting " 2>&1" just before " <<EOF". Then you should be able to inspect $sftp_log for the error message with a regular expression.

Hope this helps,
-- Hauke D

  • Comment on Re: In Perl, how to check for the remote folder existence using sftp command? Cant use Net:SFTP
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: In Perl, how to check for the remote folder existence using sftp command? Cant use Net:SFTP
by Yedu (Acolyte) on May 25, 2016 at 15:12 UTC
    When I tried to use these modules IPC::Run3 and Capture::Tiny I am getting error like Can't locate IPC/Run3.pm and Can't locate Capture/Tiny.pm respectively. Does that mean, the modules are need to be installed? Please help.
        So, is it impossible without installing any of these modules? or Is there a way to handle this situation like in shell script? Thanks...

      Yes, it means they need to be installed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1164081]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-24 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found