class

SSH2::Session

Inherits Reference / Object

Constants

INTERACTIVE_CB = Proc(::Pointer(UInt8), Int32, ::Pointer(UInt8), Int32, Int32, ::Pointer(Void), ::Pointer(LibSSH2::Password), ::Pointer(Void), Void).new do |name, name_len, instruction, instruction_len, num_prompts, _prompts, responses, data| if num_prompts > 0 uname = name.null? ? "" : String.new(name, name_len) welcome = instruction.null? ? "" : String.new(instruction, instruction_len) object_id = (Pointer(Pointer(Void)).new(data.address))[0].address callback = @@callbacks_lock.synchronize do @@callbacks.delete(object_id) end if callback password = callback.call(uname, welcome) pass_bytes = Pointer(UInt8).new((LibC.malloc(LibC::SizeT.new(password.bytesize))).address) password.to_slice.copy_to(pass_bytes, password.bytesize) pass = responses[0] pass.password = pass_bytes pass.length = password.bytesize.to_u32 responses.move_from(pointerof(pass), 1) end end nil end

Callbacks passed to c-code must not capture context

Constructors

new(socket : TCPSocket)
Source

Class methods

connect(host : String, port = 22)
Source
open(host : String, port = 22, &)
Source

Instance methods

authenticated?

Indicates whether or not the named session has been successfully authenticated.

Source
block_directions

Returns block direction flags

Source
blocking?

check whether the session is in blocking mode

Source
direct_streamlocal(path, host, port)

Tunnel TCP/IP connect through the SSH session to direct UNIX socket.

Source
direct_streamlocal(path, host, port, &)

Yields the tunnel channel and closes it when the block returns.

Source
direct_tcpip(host, port, source_host, source_port)

Tunnel a TCP/IP connection through the SSH transport via the remote host to a third party. Communication from the client to the SSH server remains encrypted, communication from the server to the 3rd party host travels in cleartext.

Source
direct_tcpip(host, port, source_host, source_port, &)

Yields the tunnel channel and closes it when the block returns.

Source
disconnect(reason = LibSSH2::DisconnectReason::BY_APPLICATION, description = "bye")

Send a disconnect message to the remote host associated with session, along with a description.

Source
enable_compression=(value)

When set before handshake, libssh2 will try to negotiate compression for the connection (off by default). Must be set prior to handshake.

Source
enable_sigpipe=(value)

When set, libssh2 lets SIGPIPE fire from the underlying socket instead of blocking it.

Source
finalize
Source
forward_listen(host, port, queue_maxsize = 16)

Instruct the remote SSH server to begin listening for inbound TCP/IP connections. New connections will be queued by the library until accepted by Listener.accept.

Source
handshake

Begin transport layer protocol negotiation with the connected host.

Source
hashkey(type : LibSSH2::HashType = LibSSH2::HashType::SHA256)

Returns the current session's host key

Source
hostkey

Returns a tuple consisting of the computed digest of the remote system's hostkey and its type.

Source
interactive_login(username, &callback : Proc(String, String, String))

Login with an interactive password

Source
keepalive_config(interval, want_reply = true)

Configure how often keepalive messages should be sent. interval is in seconds (0, the default, disables keepalive); want_reply asks the remote to acknowledge each keepalive. Must be called after handshake.

Source
knownhosts

Return KnownHosts object that allows managing known hosts

Source
login(username : String, password : String)

Login with username and password

Source
login_with_agent(username : String)

Login with username using SSH agent Warning: this method will block the crystal lang event loop. Not recommended outside of very small, limited purpose applications.

Source
login_with_data(username : String, privkey : String, pubkey : String, passphrase : String | Nil = nil)

Login with username using pub/priv key values

Source
login_with_noauth(username : String)

Send a SSH_USERAUTH_NONE request to the remote host. Unless the remote host is configured to accept none as a viable authentication scheme (unlikely), it will return SSH_USERAUTH_FAILURE along with a listing of what authentication schemes it does support. In the unlikely event that none authentication succeeds, this method with return nil. This case may be distinguished from a failing case by examining authenticated?.

Returns false value if authentication was successfull, an array of supported methods string or true otherwise

Source
login_with_pubkey(username : String, privkey : String, pubkey : String, passphrase : String | Nil = nil)

Login with username using pub/priv key files

Source
method_pref(method_type : LibSSH2::MethodType)

Returns the actual method negotiated for a particular transport parameter.

Source
nonblock_handle

Like perform_nonblock, but for libssh2 calls that return a handle/pointer (EAGAIN is detected via session_last_errno when the handle is null).

Source
open_channel(channel_type, window_size, packet_size, message)

Allocate a new channel for exchanging data with the server.

Source
open_session

Open new session channel

Source
open_session

Yields an open session channel and closes it when the block returns.

Source
perform_nonblock

Runs the block, retrying on EAGAIN (waiting on the socket in between) until libssh2 returns a real result; raises on error. Wraps calls that return an integer status. Used internally by every blocking libssh2 operation.

Source
scp_recv(path)

Request a file from the remote host via SCP.

Source
scp_recv(path, &)

Request a file from the remote host via SCP. A new channel is passed to the block and closed afterwards.

Source
scp_recv_file(path, local_path = path)

Download a file from the remote host via SCP to the local filesystem.

Source
scp_send(path, mode, size, mtime, atime)

Send a file to the remote host via SCP.

Source
scp_send(path, mode, size, mtime = Time.utc.to_unix, atime = Time.utc.to_unix, &)

Send a file to the remote host via SCP. A new channel is passed to the block and closed afterwards.

Source
scp_send_file(path, remote_path = path)

Send a file from a local filesystem to the remote host via SCP.

Source
send_keepalive

Send a keepalive message if needed. Return value indicates how many seconds you can sleep after this call before you need to call it again.

Source
set_enable_compression(value)

ameba:disable Naming/AccessorMethodName

Source
set_enable_sigpipe(value)

ameba:disable Naming/AccessorMethodName

Source
set_method_pref(method_type : LibSSH2::MethodType, value)

Set preferred methods to be negotiated. These preferences must be set prior to calling handshake, as they are used during the protocol initiation phase.

Source
sftp_session

Open a channel and initialize the SFTP subsystem. Returns a new SFTP instance

Source
sftp_session

Yields the SFTP session and closes it when the block returns.

Source
socket
Source
supported_algs(method_type : LibSSH2::MethodType)

Get a list of supported algorithms for the given method_type.

Source
timeout

Returns the timeout (in milliseconds) for how long a blocking the libssh2 function calls may wait until they consider the situation an error and raise an exception

Source
timeout=(value)

Set the timeout in milliseconds for how long a blocking the libssh2 function calls may wait until they consider the situation an error and raise an exception.

Source
to_unsafe
Source
trace(bitmask : LibSSH2::Trace)

Set the trace option. Only available if libssh2 is compliled with debug mode.

Source
verify_known_host(name : String, port : Int32, path : String = File.expand_path("~/.ssh/known_hosts", home: true)) : LibSSH2::KnownHostCheck

Verifies the session's host key against an OpenSSH known_hosts file, returning the raw verdict. Encapsulates the host-key-type -> typemask mapping so callers do not have to. A missing file yields NOTFOUND; an unknown key type yields FAILURE.

Source

Nested types