Mailing List Archive

ssh needs a default port specified
Hi,

Just ran accross this on a 2.0 install:

[Wed Jun 9 03:21:36 2010] [error] [client 154.20.204.91] Unable to
login to remote server 'xxx'.: Net::SSH2::connect: failed to connect to xxx::
Invalid argument at /var/home/xxx/bricolage/lib/Bric/Util/Trans/SFTP.pm line 139

Net::SSH2 doesn't like being called without a port:

--- SFTP.pm.orig 2010-04-11 12:57:39.000000000 -0700
+++ SFTP.pm 2010-06-09 10:30:49.000000000 -0700
@@ -131,6 +131,7 @@
# Instantiate a Net::SSH2 object and login.

my ($hn, $port) = split /:/, $s->get_host_name;
+ $port ||= 22;
my $user = $s->get_login;
my $password = $s->get_password;

@@ -264,6 +265,7 @@

# Instantiate a Net::SSH2 object and login.
my ($hn, $port) = split /:/, $s->get_host_name;
+ $port ||= 22;
my $user = $s->get_login;
my $password = $s->get_password;

and was failing to connect without defaulting it to 22. Looking at our
Net::SSH2, it has:

if (@_ == 2) {
require IO::Socket::INET;
$sock = IO::Socket::INET->new(PeerHost => $_[0], PeerPort => $_[1]);
croak "Net::SSH2::connect: failed to connect to $_[0]:$_[1]: $!"
unless $sock;

$sock->sockopt(SO_LINGER, pack('SS', 0, 0));
}

so I think you need to default it to 22.

Cheers,

Alex

--
Alex Krohn <alex@gossamer-threads.com>
Re: ssh needs a default port specified [ In reply to ]
On Jun 9, 2010, at 10:39 AM, Alex Krohn wrote:

> so I think you need to default it to 22.

It also works if you pass no port argument at all. My refactor has changed the code to:

$ssh2->connect(split /:/ => $hn)

So it will only pass the port if there is one specified in the host name.

Thanks,

David
Re: ssh needs a default port specified [ In reply to ]
David,

Thanks for the work! I will definitely test this in the next day or so.

-Matt

On Jul 6, 2010, at 5:34 PM, David E. Wheeler wrote:

> On Jun 9, 2010, at 10:39 AM, Alex Krohn wrote:
>
>> so I think you need to default it to 22.
>
> It also works if you pass no port argument at all. My refactor has changed the code to:
>
> $ssh2->connect(split /:/ => $hn)
>
> So it will only pass the port if there is one specified in the host name.
>
> Thanks,
>
> David
>