Skip to content

Instantly share code, notes, and snippets.

@kingsleyh
Created July 15, 2018 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingsleyh/5a5f7a58fa9ac980d90c00785d86f02e to your computer and use it in GitHub Desktop.
Save kingsleyh/5a5f7a58fa9ac980d90c00785d86f02e to your computer and use it in GitHub Desktop.
ssh2
require "ssh2"
SSH2::Session.open("localhost", 22) do |session|
session.login("test", "password")
session.open_session do |ch|
ch.request_pty("vt100")
ch.shell
session.blocking = false
buf_space = uninitialized UInt8[1024]
buf = buf_space.to_slice
spawn do
ch.write(gets.to_slice)
end
spawn do
if ch.socket
len = ch.read(buf).to_i32
print String.new buf[0, len]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment