Mailing List Archive

SFTP problem
Hello,

I have a little problem: i publish my stories on my destination server
via SFTP, for security reasons i changed the sshd port of my destination
server. I changed the host name of my destination server from
192.168.1.1 to 192.168.1.1:2022 whishing it will work but it didn't.

i get this error:

Can't connect to 192.168.1.1, port 22: Connection refused at /usr/lib/perl5/vendor_perl/5.8.8/Net/SSH/Perl.pm line 208, <GEN752> line 91

it did not recognize the host:port syntax

i don't if this is possible in newer versions of bricolage since this is version 1.10.3

thanks for the help
Re: SFTP problem [ In reply to ]
On Wed, Nov 25, 2009 at 12:49 AM, Ivan -sk8- Chavero
<ichavero@seispistos.com.mx> wrote:
> I have a little problem: i publish my stories on my destination server
> via SFTP, for security reasons i changed the sshd port of my destination
> server. I changed the host name of my destination server from
> 192.168.1.1 to 192.168.1.1:2022 whishing it will work but it didn't.
>
> i get this error:
>
> Can't connect to 192.168.1.1, port 22:

In both put_res and del_res, the port is explicitly stripped off:
http://github.com/bricoleurs/bricolage/blob/9a07533e9912a6abd00f5ce1218ff787593b8bfa/lib/Bric/Util/Trans/SFTP.pm

(my $hn = $s->get_host_name) =~ s/:\d+$//;
....
$ssh2->connect($hn);

Easy to make it work with Net::SSH2:
http://search.cpan.org/dist/Net-SSH2/lib/Net/SSH2.pm#connect_%28_handle_|_host_[,_port_[,_Timeout_=%3E_secs_]]_%29
Re: SFTP problem [ In reply to ]
On Nov 25, 2009, at 4:23 PM, lannings@gmail.com wrote:

> In both put_res and del_res, the port is explicitly stripped off:
> http://github.com/bricoleurs/bricolage/blob/9a07533e9912a6abd00f5ce1218ff787593b8bfa/lib/Bric/Util/Trans/SFTP.pm
>
> (my $hn = $s->get_host_name) =~ s/:\d+$//;
> ....
> $ssh2->connect($hn);
>
> Easy to make it work with Net::SSH2:
> http://search.cpan.org/dist/Net-SSH2/lib/Net/SSH2.pm#connect_%28_handle_|_host_[,_port_[,_Timeout_=%3E_secs_]]_%29

Oh, yeah, that should be fixed. Any takers?

Best,

David
Re: SFTP problem [ In reply to ]
The problem is in the $sftp_args function, i've modified it for my
actual version (1.10.3) but i'll modify the svn version during the day
and send the patch to the list



here's the function for 1.10.3

$sftp_args = sub {
my $server = shift;

# Set up the SSH arguments. Make sure we're never mistaken for root.
# by setting privileged => 0. This comes up with bric_queued.
my @ssh_args = (privileged => 0);
#separate the hostname and port
my ($hn, $port) = split(/:/, $server->get_host_name);
$port = ($port !~ /\d+/ || $port eq "") ? 22 : $port;
if (ENABLE_SFTP_V2 || SFTP_MOVER_CIPHER) {
push @ssh_args, protocol => '2,1' if ENABLE_SFTP_V2;
push @ssh_args, cipher => SFTP_MOVER_CIPHER if SFTP_MOVER_CIPHER;
push @ssh_args, port => $port;
}

return (
$hn,
debug => DEBUG,
ssh_args => \@ssh_args,
user => $server->get_login,
password => $server->get_password
);
};


hope this helps


David E. Wheeler wrote:
> On Nov 25, 2009, at 4:23 PM, lannings@gmail.com wrote:
>
>
>> In both put_res and del_res, the port is explicitly stripped off:
>> http://github.com/bricoleurs/bricolage/blob/9a07533e9912a6abd00f5ce1218ff787593b8bfa/lib/Bric/Util/Trans/SFTP.pm
>>
>> (my $hn = $s->get_host_name) =~ s/:\d+$//;
>> ....
>> $ssh2->connect($hn);
>>
>> Easy to make it work with Net::SSH2:
>> http://search.cpan.org/dist/Net-SSH2/lib/Net/SSH2.pm#connect_%28_handle_|_host_[,_port_[,_Timeout_=%3E_secs_]]_%29
>>
>
> Oh, yeah, that should be fixed. Any takers?
>
> Best,
>
> David
>
>
Re: SFTP problem [ In reply to ]
On Nov 26, 2009, at 1:52 AM, Iván Chavero wrote:

> The problem is in the $sftp_args function, i've modified it for my
> actual version (1.10.3) but i'll modify the svn version during the day
> and send the patch to the list
>
>
>
> here's the function for 1.10.3

And here is the patch for 1.11.x. Would someone try this out, please.

--- a/lib/Bric/Util/Trans/SFTP.pm
+++ b/lib/Bric/Util/Trans/SFTP.pm
@@ -133,13 +133,13 @@ sub put_res {

# Instantiate a Net::SSH2 object and login.

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

my $ssh2 = Net::SSH2->new();
my $connect = eval {
- $ssh2->connect($hn);
+ $ssh2->connect($hn, $port);
$ssh2->method('CRYPT_CS', SFTP_MOVER_CYPHER ) if SFTP_MOVER_CIPHER;
$ssh2->auth( username => $user, password => $password );
};
@@ -266,13 +266,13 @@ sub del_res {
next unless $s->is_active;

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

my $ssh2 = Net::SSH2->new();
my $connect = eval {
- $ssh2->connect($hn);
+ $ssh2->connect($hn, $port);
$ssh2->method('CRYPT_CS', SFTP_MOVER_CYPHER ) if SFTP_MOVER_CIPHER;
$ssh2->auth( username => $user, password => $password );
};

Thanks,

David
Re: SFTP problem [ In reply to ]
On Nov 27, 2009, at 8:07 PM, David E. Wheeler wrote:

> And here is the patch for 1.11.x. Would someone try this out, please.

And for 1.10.x. Again, someone please test:

--- a/lib/Bric/Util/Trans/SFTP.pm
+++ b/lib/Bric/Util/Trans/SFTP.pm
@@ -355,13 +355,14 @@ $sftp_args = sub {
push @ssh_args, cipher => SFTP_MOVER_CIPHER if SFTP_MOVER_CIPHER;
}

- (my $hn = $server->get_host_name) =~ s/:\d+$//;
+ my ($hn, $port) = split /:/, $server->get_host_name;
return (
$hn,
debug => DEBUG,
ssh_args => \@ssh_args,
user => $server->get_login,
- password => $server->get_password
+ password => $server->get_password,
+ ($port ? (port => $port) : ()),
);
};


Best,

David