Patch for Net::SSH::Perl
Today I ran into an issue with one of my scripts which is generating a report and uploads it to the customer site via FTP. I lately added a SFTP features, as this was a requirement by one customer. To accomplish this, I used the Net::SFTP module which uses Net::SSH::Perl to connect to the SSH server. While I programmed the script all tests worked fine, but when I tried to get it running in production for the customer it was failing.
The debug output of Net::SFTP looked like this:
hostname: Authentication methods that can continue: publickey,password,keyboard-interactive.
hostname: Next method to try is publickey.
hostname: Trying pubkey authentication with key file '/export/home/someuser/.ssh/id_rsa'
hostname: Login completed, opening dummy shell channel.
hostname: channel 0: new [client-session]
hostname: Requesting channel_open for channel 0.
hostname: channel 0: open confirm rwindow 0 rmax 34000
[ERROR] Connection to SFTP failed -> Could not dupe: No such file or directory
After digging a bit deeper into this, I figured that Net::SFTP was failing while calling Net::SSH::Perl's _session_channel() function- and within this function the $cmgr->new_channel() function was failing while calling the _dup() function. This function seems to hijack a stream and duplicate it into a new FH. And here is where the problem was. In the _dup() function the original code uses:
which is incorrect and caused the problem. So I created a patch for this file to correct this issue.
Here it is:
+++ SSH2.pm Tue Jan 20 12:10:37 2009
@@ -25,4 +25,3 @@
my $dup = Symbol::gensym;
- my $str = "${mode}&$fh&"
- open $dup, '<', $str or die "Could not dupe: $!\n";
+ open($dup, "${mode}&=$fh") or die "Could not dupe: $!\n";
$dup;


