This repository has been archived by the owner. It is now read-only.
ssh.cr
SSH.cr
SSH client in Crystal and bindings for LibSSH.
Installation
- Install libssh development headers:
apt install libssh-dev
# or
dnf install libssh-devel
-
Add the dependency to your
shard.yml
:dependencies: ssh: github: 84codes/ssh.cr
-
Run
shards install
Usage
require "ssh"
SSH.open("localhost", "root", 22) do |ssh|
# execute command and collect all output in a string
output, exit_status = ssh.exec! "echo Hello world"
# execute a command and do something with the output
ssh.exec("echo hello world") do |bytes, is_stderr|
if is_stderr
STDERR.write bytes
else
STDOUT.write bytes
end
end
# More control and can write the the STDIN
ssh.channel do |ch|
ch.on_data do |bytes, is_stderr|
STDOUT.write bytes
end
ch.exec("cat")
ch.puts "hello world"
ch.eof! # closes stdin on the server side
ch.wait # wait for the channel to close
puts "Exited with status: #{ch.exit_status}"
end
end
Development
The specs requires you to run a local sshd server instance, which requires sudo to be run. That's why you're asked for your password when running specs.
Contributing
- Fork it (https://github.com/84codes/ssh.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Carl Hörberg - creator and maintainer
Repository
ssh.cr
Owner
Statistic
- 0
- 0
- 0
- 1
- 0
- over 1 year ago
- October 17, 2022
License
MIT License
Links
Synced at
Thu, 16 May 2024 19:47:18 GMT
Languages