Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Net::SFTP does not catch errors

by lsherwood (Sexton)
on Dec 30, 2007 at 03:19 UTC ( #659556=note: print w/replies, xml ) Need Help??


in reply to Net::SFTP does not catch errors

I've noticed a similar "feature" when using 'get' with Net::SFTP. Allow me to expand on your comment a bit, as I suspect 'get' and 'put' operate identically in this regard. Here is some code very similar to yours, using 'get':
eval { $sftp->get($remote_file, $local_file) or die "GET FAILED"; }; print "eval says: $@" if $@;
The problem is that with the 'die' statement present in the get command, the 'die' phrase is passed to $@ whether or not the get command succeeds. As best I can determine, this is a flaw, or at least a limitation, in Net::SFTP. In addition, even when not using the eval statement to enclose the sftp->get command, a die statement is executed even when the 'get' command succeeds. This kills the script right after completing the 'get'.

Removing the 'die' statement but keeping the eval in place results in:

1) No $@ generated if the get succeeds -- this is fine;

2) $@ is created if the get fails and the problem is with the local file path;

3) No $@ generated if the get fails and the problem is in the remote file path -- the get failure remains undetected by eval and so it is not stored in $@.

It appears to me that:

a) die should not be used with $sftp->get commands because even on a successful 'get';

.... i) if eval is used, an unwanted $@ is created from the 'die' statement;

.... ii) if eval is not used the 'die' kills the feed script (although the get succeeds);

b) Eval should be used to generate $@ so that get 'failures' related to the local file path are detected;

c) Using eval does not fully verify the get succeeded because it will ignore get failures due to problems with the remote file path.

If anyone knows a workaround to this limitation with Net::SFTP, please post it here.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2018-09-20 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (177 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!