cannot use shell example
Opened this issue · 1 comments
despiegk commented
require "ssh2"
SSH2::Session.open("localhost",port=5001) do |session|
session.login_with_agent("root")
session.open_session do |channel|
channel.command("uptime")
IO.copy(channel, STDOUT)
end
session.open_session do |ch|
ch.request_pty("vt100")
ch.shell
session.blocking = false
buf_space = Bytes.new(1024)
buf = buf_space.to_slice
loop do
io = IO.select([STDIN, ch.socket]).first
if io == STDIN
command = gets
if command
ch.write(command.to_slice)
end
elsif io == ch.socket
len = ch.read(buf).to_i32
print! String.new buf[0, len]
break if ch.eof?
end
end
end
end
In src/builder.cr:26:13
26 | session.blocking = false
^-------
Error: private method 'blocking=' called for SSH2::Session
JSX:OSX:builder: docker images
(reverse-i-search)`sh': ssh-add -l
JSX:OSX:builder: shards install
Resolving dependencies
Fetching https://github.com/spider-gazelle/ssh2.cr.git
Installing ssh2 (1.2.6 at cc5af1d6fcfbf4c72784e1c2445bddb678880e27)
Writing shard.lock
JSX:OSX:builder: crystal run src/builder.cr
Showing last frame. Use --error-trace for full trace.
In src/builder.cr:25:13
25 | session.blocking = false
^-------
Error: private method 'blocking=' called for SSH2::Session
stakach commented
Does it work if you remove the blocking line?
As we basically never want to block as it'll block the crystal reactor loop.
I didn't actually write the examples but this is how I use it in production:
https://github.com/PlaceOS/driver/blob/master/src/driver/transport/ssh.cr