Errno::ECONNREFUSED in net/ssh

Hi,
I need to automate the ssh connection for that i wrote the small snippet
but the error shows its not able to communicate with the remote machine
using the below code. Please provide the solution.


Note:

  1. Telnet service is not available on the remote machine
  2. I am able to execute the command manually using Putty

###------------
##My code:
###-----------

#!/usr/bin/ruby

require ‘rubygems’
require ‘net/ssh’

def SetSsh(command)

Net::SSH.start($ipdddr, “username”, :password => “password”) do|ssh|
result = ssh.exec!(command)
puts “result = #{result}”
end
end

Main program execution
SetSsh(“ls -l”)
##########-End of File.


Error Which i received:

C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:in
initialize’: No connection could be made because the target machine
actively refused it. - connect(2) (Errno::ECONNREFUSED)
from
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:inopen’
from
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:in
initialize’
from C:/Ruby187/lib/ruby/1.8/timeout.rb:53:intimeout’
from C:/Ruby187/lib/ruby/1.8/timeout.rb:101:in timeout’
from
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh/transport/session.rb:67:ininitialize’
from
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh.rb:186:in
new’
from
C:/Ruby187/lib/ruby/gems/1.8/gems/net-ssh-2.6.1/lib/net/ssh.rb:186:instart’
from File_name.rb:49:in `SetSsh’
from File_name.rb:338

Hi,

Had the same problem, solved by changing username/password by a
variable.

Example:

#!/usr/bin/env ruby
require ‘rubygems’
require ‘net/ssh’

host = ‘x.x.x.x’
user = ‘user’
pass = ‘password’

Net::SSH.start( host, user, :password => pass ) do|ssh|
result = ssh.exec!(‘ps -ef’)
puts result
end

Luc.

On Thu, Nov 22, 2012 at 1:33 PM, Sambath Kumar Moorthy
<[email protected]

How to cleanly catch this exception ?

Luc E. wrote in post #1085943:

Hi,

Had the same problem, solved by changing username/password by a
variable.

Example:

Luc.

On Thu, Nov 22, 2012 at 9:27 PM, Luc E. [email protected] wrote:

Had the same problem, solved by changing username/password by a
variable.

How the heck is that supposed to remedy a network connection error? The
latter has nothing to do with how you provide arguments to Net::SSH.
It’s
rather which arguments you pass. The original code for example did
not
contain an assignment to $ipdddr…

And please trim your quotes.

Cheers

robert