note
lsherwood
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':
<code>
eval {
$sftp->get($remote_file, $local_file) or die "GET FAILED";
};
print "eval says: $@" if $@;
</code>
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'.<p>
Removing the 'die' statement but keeping the eval in place results in:<p>
1) No $@ generated if the get succeeds -- this is fine;<p>
2) $@ is created if the get fails and the problem is with the local file path;<p>
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 $@.<p>
It appears to me that:<p>
a) die should not be used with $sftp->get commands because even on a successful 'get';<p>....
i) if eval is used, an unwanted $@ is created from the 'die' statement;<p>....
ii) if eval is not used the 'die' kills the feed script (although the get succeeds);<p>
b) Eval should be used to generate $@ so that get 'failures' related to the local file path are detected;<p>
c) Using eval does not fully verify the get succeeded because it will ignore get failures due to problems with the remote file path.<p>
If anyone knows a workaround to this limitation with Net::SFTP, please post it here.
295431
295431