Thread

Posted on Thu Jun 29 16:20:10 2006 by blankt
unhappy with missing incomplete error handling
As I've already reported in Bug #16629, I'm quite unhappy with the missing/incomplete error handling and false exit codes. Studying the Foreign.pm you see that these exit codes do NOT come from the ssh binary but from
Carp::croak()

Some situations where I expect a useful error handling:
1. hostname cannot be resolved
2. no ssh-daemon running on host
3. wrong username/password
4. rejected public key
5. every open/close/chmod/binmode/... operation
6. maybe some more

3. can be fixed by ssh_config-parameters:
Instead of using password challange, use a public key with an empty passphrase or a ssh-agent instead and add the following configs to the constructor:
"-oPreferredAuthentications=publickey","-oPasswordAuthentication=no","-oBatchMode=yes"

To fix the other points, the code of Foreign.pm must be changed:
In general: do NOT use Carp::croak but set
$sftp->warn(...)
and return undef
After calling open2() in sub new(), check to see if the forked process is still running and not in defunct state. Sleep one second before doing so. The open2-call itself should be surrounded by eval{} to suppress its errors.
Think about replacing open2 with open3. open3 is cappable of returning STDERR.

I hacked Foreign.pm with the mentioned improvements (really, it is a hack...) and yes, it works for me. I'm sure that other users will profit from the changes. I used version 0.57, but 0.60 (and the latest dev-codes) do not work different.
If you're interested in, please leave me a message and I will send you the code (it's not enough room to paste it in here).
Thanks
Direct Responses: 2557 | Write a response
Posted on Thu Jun 29 16:53:00 2006 by salva in response to 2556
Re: unhappy with missing incomplete error handling
Please, don't use this forum to discuss Net::SFTP::Foreign. Send my your comments by email or use the bugtracker at http://rt.perl.org .

Thank you.

Write a response