Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/datanoise/ssh2.cr
libssh2 binding for Crystal language
https://github.com/datanoise/ssh2.cr
Last synced: 12 days ago
JSON representation
libssh2 binding for Crystal language
- Host: GitHub
- URL: https://github.com/datanoise/ssh2.cr
- Owner: datanoise
- License: mit
- Archived: true
- Created: 2015-05-29T16:45:05.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-14T09:41:51.000Z (about 4 years ago)
- Last Synced: 2024-03-04T07:36:48.720Z (4 months ago)
- Language: Crystal
- Size: 43.9 KB
- Stars: 41
- Watchers: 7
- Forks: 14
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-crystal - ssh2.cr - Bindings for libssh2 library (C bindings)
- awesome-crystal - ssh2.cr - Library that provides binding for libssh2 library (Networking)
README
# ssh2.cr
This library provides binding for libssh2 library.
# Status
*Alpha*
# Requirements
- Crystal language version 0.17 and higher.
- libssh2 version 1.5.0 or higherYou can use `homebrew` to install the latest libssh2:
```
$ brew install libssh2
```# Goal
The goal is to utilize libssh2 API by providing services like ability to run
shell commands via ssh as well as scp and sftp services.# Usage
An example of running a shell command via SSH on the remote server:
```crystal
require "./src/ssh2"SSH2::Session.open("my_server") do |session|
session.login("username", "password")
session.open_session do |channel|
channel.command("uptime")
IO.copy(channel, STDOUT)
end
end
```An example of running shell:
```crystal
require "./src/ssh2"SSH2::Session.open("localhost", 2222) do |session|
session.login_with_pubkey("root", "./spec/keys/id_rsa")
session.open_session do |ch|
ch.request_pty("vt100")
ch.shell
session.blocking = falsebuf_space = uninitialized UInt8[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
```An example of using SFTP API:
```crystal
require "./src/ssh2"SSH2::Session.open("localhost", 2222) do |session|
session.login_with_pubkey("root", "./spec/keys/id_rsa")
session.sftp_session do |sftp|
sftp.open_dir(".").ll do |fn|
puts fn
end
file = sftp.open(".bashrc")
puts file.gets_to_end
end
end
```# Testing
In order to run test suite you need to pull and run the following docker container:
```
$ docker pull tutum/ubuntu:trusty
$ docker run -d -p 2222:22 -e AUTHORIZED_KEYS="`cat ./spec/keys/id_rsa.pub`" tutum/ubuntu:trusty
```# License
MIT clause - see LICENSE for more details.