Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot use shell example #7

Open
despiegk opened this issue Apr 20, 2020 · 1 comment
Open

cannot use shell example #7

despiegk opened this issue Apr 20, 2020 · 1 comment

Comments

@despiegk
Copy link

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
Copy link
Member

stakach commented Apr 20, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants