Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: Net::SFTP does not catch errors by lsherwood
in thread Net::SFTP does not catch errors by mikedshelton

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (5)
    As of 2019-02-22 02:22 GMT
    Find Nodes?
      Voting Booth?
      I use postfix dereferencing ...

      Results (115 votes). Check out past polls.

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