|
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
|