[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] Net::SSH 0.9.0

Jamis Buck

1/11/2005 9:52:00 PM

Net::SSH is a pure-Ruby implementation of an SSH2-compatible client.
It allows Ruby scripts to programmatically interact with remote
processes via SSH. It currently only supports version 2 of the SSH
protocol.

project page: http://rubyforge.org/projec...
user manual: http://net-ssh.rub...
API docs: http://net-ssh.rub.../api

This release is (tentatively) the first in a series of beta releases
designed to get Net::SSH to 1.0 release status as soon as possible. It
includes the following feature additions and bug fixes:

* Added 'shell' and 'sync' services for interacting with users'
shells, including a demo script that uses these to implement a
simple SSH terminal client.

* The 'keyboard-interactive' authentication method is implemented
correctly now, which means users may receive a prompt to enter
a password if one is not given, and is required.

* The bug that caused the agent to always be used--even if it was
unavailable--has been fixed.

* The user manual now includes links to previous/next chapters, and
uses syntax highlighting for the code blocks. Various other style
tweaks in the manual.

* Window sizes and maximum packet sizes are now honored, which should
take care of various bugs and make Net::SSH play nicer with older
SSH servers.

* Non-blocking reads are now supported via the
Transport::Session#reader_ready? method. The
Connection::Driver#process method has been modified to make better
use of this.

* Moved to subversion, from CVS. Repository is now at
http://www.jamisbuck.org/s...

Please experiment with this release and report any bugs. Also, for
some reason the (now-ancient) 0.1.0 release of Net::SSH seems to be
a very popular gem download... if you are one of those that prefers
the 0.1.0 release to the current release, please drop me a line and
let me know why that is, so that I can make later release as
palatable. Thanks!

--
Jamis Buck
jamis_buck@byu.edu
http://www.jamisbuck...
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."



11 Answers

James Britt

1/12/2005 2:53:00 AM

0

Jamis Buck wrote:
> Net::SSH is a pure-Ruby implementation of an SSH2-compatible client.
> It allows Ruby scripts to programmatically interact with remote
> processes via SSH. It currently only supports version 2 of the SSH
> protocol.


Hey, Jamis, get some sleep!

Syntax, Net::SHH ...

I expect a new Needle any minute now.


James


Dominik Werder

1/12/2005 11:38:00 AM

0

I get the following error when I start an example.
I installed net-ssh and needle with gems, I have ruby 1.8.2:


my$ ruby ssh-client.rb
.../lib/net/ssh/session.rb:17:in `require': No such file to load -- needle
(LoadError)
from ../lib/net/ssh/session.rb:17
from ../lib/net/ssh.rb:17:in `require'
from ../lib/net/ssh.rb:17
from ssh-client.rb:21:in `require'
from ssh-client.rb:21

Jamis Buck

1/12/2005 2:42:00 PM

0

On 20:41 Wed 12 Jan , Dominik Werder wrote:
> I get the following error when I start an example.
> I installed net-ssh and needle with gems, I have ruby 1.8.2:
>
>
> my$ ruby ssh-client.rb
> ..../lib/net/ssh/session.rb:17:in `require': No such file to load -- needle
> (LoadError)
> from ../lib/net/ssh/session.rb:17
> from ../lib/net/ssh.rb:17:in `require'
> from ../lib/net/ssh.rb:17
> from ssh-client.rb:21:in `require'
> from ssh-client.rb:21

Can you try executing:

gem -v

and

echo $RUBYOPT

and

ruby -e 'require "needle"; p Needle::Registry'

It sounds like either needle didn't actually get installed (odd,
because net-ssh shouldn't install if the needle dependency isn't
satisfied), or you don't have the RUBYOPT environment variable set up
(should be at least "RUBYOPT=rubygems").

- Jamis

--
Jamis Buck
jamis_buck@byu.edu
http://www.jamisbuck...
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."



Dominik Werder

1/15/2005 3:41:00 PM

0

> It sounds like either needle didn't actually get installed (odd,
> because net-ssh shouldn't install if the needle dependency isn't
> satisfied), or you don't have the RUBYOPT environment variable set up
> (should be at least "RUBYOPT=rubygems").

You're right, $RUBYOPT was empty. Never heard about this variable..
Now it's working and I will explore a bit..

bye!
Dominik

ckennedy2

2/10/2005 8:53:00 PM

0

Hello, I have a question and hope this is the correct area for it. If not
please feel free to direct me elsewhere.

Q:
I'm looking to implement an SSH based script/utility to connect to 8
different boxen, execute various commands and retrieve a file. The Perl
and Ant SSH implementation just don't seem to have what I need. I've
checked into this Ruby implementation and like it the best. I'm having a
problem tho, here's the code, based off Jamis' examples. Also the problem
seem to be when I call my method , @server isn't being recognized by my
Net:SSH call (getting socket error):

Code:

require 'net/ssh'


def do_sshget (sshserver)


@sshserver = sshserver

Net::SSH.start(
"@sshserver", 'user', 'passw',
:keys=>["C:\SSH\HostKeys"]
) do |session|
shell = session.shell.open
shell.send_data "/home/user/bin/copy_log\n"
shell.exit
sleep 10.0
$stdout.print shell.stdout while shell.stdout?
$stderr.puts "-- stderr: --"
$stderr.print shell.stderr while shell.stderr?

end

# Copy the logs locally, can't find SCP in Ruby, shelling out to
Putty's pscp.exe
f=IO.popen("pscp -pw pass
user@"@sshserver":/home/user/log_archive/@sshserver.jar @sshserver.jar")
p f.readlines


end

#Need to repeat this 7 more times 'somehow' with different server name
do_sshget("server123456")




ERROR:
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in
`initialize':
getaddrinfo: no address associated with hostname. (SocketError)
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in `
open'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in `
initialize'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/services.rb:121:in
`new'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/services.rb:121:in
`register_services'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/services.rb:115:in
`call'
from
C:/ruby/lib/ruby/gems/1.8/gems/needle-1.2.0/lib/needle/lifecycle/si
ngleton.rb:42:in `call'
from
C:/ruby/lib/ruby/gems/1.8/gems/needle-1.2.0/lib/needle/lifecycle/si
ngleton.rb:40:in `synchronize'
from
C:/ruby/lib/ruby/gems/1.8/gems/needle-1.2.0/lib/needle/lifecycle/si
ngleton.rb:40:in `call'
... 25 levels...
from C:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:47:in `new'
from C:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:47:in `start'
from log_get.rb:7:in `do_sshget'
from log_get.rb:27


ckennedy2

2/10/2005 8:54:00 PM

0

Hello, I have a question and hope this is the correct area for it. If not
please feel free to direct me elsewhere.

Q:
I'm looking to implement an SSH based script/utility to connect to 8
different boxen, execute various commands and retrieve a file. The Perl
and Ant SSH implementation just don't seem to have what I need. I've
checked into this Ruby implementation and like it the best. I'm having a
problem tho, here's the code, based off Jamis' examples. Also the problem
seem to be when I call my method , @server isn't being recognized by my
Net:SSH call (getting socket error):

Code:

require 'net/ssh'


def do_sshget (sshserver)


@sshserver = sshserver

Net::SSH.start(
"@sshserver", 'user', 'passw',
:keys=>["C:\SSH\HostKeys"]
) do |session|
shell = session.shell.open
shell.send_data "/home/user/bin/copy_log\n"
shell.exit
sleep 10.0
$stdout.print shell.stdout while shell.stdout?
$stderr.puts "-- stderr: --"
$stderr.print shell.stderr while shell.stderr?

end

# Copy the logs locally, can't find SCP in Ruby, shelling out to
Putty's pscp.exe
f=IO.popen("pscp -pw pass
user@"@sshserver":/home/user/log_archive/@sshserver.jar @sshserver.jar")
p f.readlines


end

#Need to repeat this 7 more times 'somehow' with different server name
do_sshget("server123456")




ERROR:
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in
`initialize':
getaddrinfo: no address associated with hostname. (SocketError)
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in `
open'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in `
initialize'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/services.rb:121:in
`new'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/services.rb:121:in
`register_services'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/services.rb:115:in
`call'
from
C:/ruby/lib/ruby/gems/1.8/gems/needle-1.2.0/lib/needle/lifecycle/si
ngleton.rb:42:in `call'
from
C:/ruby/lib/ruby/gems/1.8/gems/needle-1.2.0/lib/needle/lifecycle/si
ngleton.rb:40:in `synchronize'
from
C:/ruby/lib/ruby/gems/1.8/gems/needle-1.2.0/lib/needle/lifecycle/si
ngleton.rb:40:in `call'
... 25 levels...
from C:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:47:in `new'
from C:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:47:in `start'
from log_get.rb:7:in `do_sshget'
from log_get.rb:27


Jamis Buck

2/10/2005 9:18:00 PM

0

On 05:55 Fri 11 Feb , ckennedy2 wrote:
> Hello, I have a question and hope this is the correct area for it. If not
> please feel free to direct me elsewhere.
>
> Q:
> I'm looking to implement an SSH based script/utility to connect to 8
> different boxen, execute various commands and retrieve a file. The Perl
> and Ant SSH implementation just don't seem to have what I need. I've
> checked into this Ruby implementation and like it the best. I'm having a
> problem tho, here's the code, based off Jamis' examples. Also the problem
> seem to be when I call my method , @server isn't being recognized by my
> Net:SSH call (getting socket error):
>
> Code:
>
> require 'net/ssh'
>
>
> def do_sshget (sshserver)
>
>
> @sshserver = sshserver
>
> Net::SSH.start(
> "@sshserver", 'user', 'passw',
^^^^^^^^^^^^

The problem is right there. Just use the sshserver variable directly,
like this:

Net::SSH.start( sshserver, 'user', 'passw',
:keys=>["C:\\SSH\\HostKeys"] )

Also, note that the backslashes are escpaed in the keys
string.

If you want to use string interpolation (where you specify an
expression inside the string and have it evaluated in the string), use
the "#{...}" syntax:

"#{@sshserver}"

> # Copy the logs locally, can't find SCP in Ruby, shelling out to
> Putty's pscp.exe
> f=IO.popen("pscp -pw pass
> user@"@sshserver":/home/user/log_archive/@sshserver.jar @sshserver.jar")
> p f.readlines

Can you use SFTP? I'm "kind of" working on an SCP module for Ruby, but
it's hard going (the protocol is not documented at all, so I'm having
to extract it from the source code). In the meantime, there is
a pretty fully-functioning SFTP module for Ruby:

Net::SFTP.open( @sshserver, 'user', 'passw' ) do |sftp|
sftp.open_handle (
"/home/user/log_archive/#{@sshserver}.jar"
) do |handle|
log = sftp.read( handle )
p log
end
end

Hope that helps,

Jamis


--
Jamis Buck
jamis_buck@byu.edu
http://jamis.jam...
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."



ckennedy2

2/10/2005 10:00:00 PM

0

First, thanks for responding so quick!

I've been trying various syntaxes, and reading the online book for ruby. I
tried your syntax above to no avail. I even tried setting the argument to
another variable name and using it instead like:

CODE:
def do_sshget (sshserver)


sserver = sshserver

Net::SSH.start(sserver, ...
...
end

And just
CODE:
def do_sshget (sshserver)



Net::SSH.start(sshserver, ...
...
end

************************
I call with :
do_sshget("someserver123")
To no avail, same error
ERROR:
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in
`initialize':
getaddrinfo: no address associated with hostname. (SocketError)
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in `
open'

********************************
:( What the heck am I doing wrong?

I don't think SFTP is installed/active on these servers. Using pscp isn't
too much of a problem tho. I get the impression that scp is becoming
deprecated throughout most languages (at least Perl) but in the real world
its still on every box ;)

Jamis Buck

2/11/2005 4:03:00 AM

0

On 07:05 Fri 11 Feb , ckennedy2 wrote:
> And just
> CODE:
> def do_sshget (sshserver)
>
>
>
> Net::SSH.start(sshserver, ...
> ...
> end

The above _should_ work fine. The error you are getting seems to
indicate that the host name you are using is misformatted somehow, but
I'm definitely not familiar with networking issues on Windows. (Is
Daniel Berger around and watching this thread? If so, any thoughts?)

>
> ************************
> I call with :
> do_sshget("someserver123")
> To no avail, same error
> ERROR:
> C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in
> `initialize':
> getaddrinfo: no address associated with hostname. (SocketError)
> from
> C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in `
> open'
>
> ********************************
> :( What the heck am I doing wrong?
>
> I don't think SFTP is installed/active on these servers. Using pscp isn't
> too much of a problem tho. I get the impression that scp is becoming
> deprecated throughout most languages (at least Perl) but in the real world
> its still on every box ;)

Yup, which is why I want to try and write this. Alas, as I mentioned,
it's a _real_ bear to implement. (Well, at least to understand. Once
understand it's actually pretty straightforward.)

- Jamis

--
Jamis Buck
jamis_buck@byu.edu
http://jamis.jam...
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."



ckennedy2

2/11/2005 2:05:00 PM

0

You were right, not sure why but after a reboot I did the following. I
backed off to hard coding it in there. And it works, then added a method
call with hard coding and it worked. Then added method argument as posted
above ... and it worked!!

Not sure why it was failing earlier, could be windows.

First, thanks for writing this API!
Second, it works great!
Third, thanks for providing answers to my questions!

If I come across any SCP documentation, I'll post it here. I'd say I'd
help but I'm just learning Ruby myself (maybe in a year or two I'll catch
up!)

Good luck !