class SSH2::Session

Defined in:

session.cr

Constant Summary

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

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(socket : TCPSocket) #

[View source]

Class Method Detail

def self.connect(host : String, port = 22) #

[View source]
def self.open(host : String, port = 22, &) #

[View source]

Instance Method Detail

def authenticated? #

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


[View source]
def banner=(value) #

Set the banner that will be sent to the remote host when the SSH session is started with #handshake. This is optional; a banner corresponding to the protocol and libssh2 version will be sent by default.


[View source]
def block_directions #

Returns block direction flags


[View source]
def blocking? #

check whether the session is in blocking mode


[View source]
def direct_streamlocal(path, host, port) #

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


[View source]
def direct_streamlocal(path, host, port, &) #

[View source]
def 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.


[View source]
def direct_tcpip(host, port, source_host, source_port, &) #

[View source]
def disconnect(reason = LibSSH2::DisconnectReason::BY_APPLICATION, description = "bye") #

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


[View source]
def enable_compression=(value) #

[View source]
def enable_sigpipe=(value) #

[View source]
def finalize #

[View source]
def 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.


[View source]
def handshake #

Begin transport layer protocol negotiation with the connected host.


[View source]
def hashkey(type : LibSSH2::HashType = LibSSH2::HashType::SHA256) #

Returns the current session's host key


[View source]
def hostkey #

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


[View source]
def interactive_login(username, &callback : Proc(String, String, String)) #

Login with an interactive password


[View source]
def knownhosts #

Return KnownHosts object that allows managing known hosts


[View source]
def login(username : String, password : String) #

Login with username and password


[View source]
def 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.


[View source]
def login_with_data(username : String, privkey : String, pubkey : String, passphrase : String | Nil = nil) #

Login with username using pub/priv key values


[View source]
def 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


[View source]
def login_with_pubkey(username : String, privkey : String, pubkey : String, passphrase : String | Nil = nil) #

Login with username using pub/priv key files


[View source]
def method_pref(method_pref : LibSSH2::MethodType) #

Returns the actual method negotiated for a particular transport parameter.


[View source]
def nonblock_handle(&) #

[View source]
def open_channel(channel_type, window_size, packet_size, message) #

Allocate a new channel for exchanging data with the server.


[View source]
def open_session #

Open new session channel


[View source]
def open_session(&) #

[View source]
def perform_nonblock(&) #

[View source]
def scp_recv(path) #

Request a file from the remote host via SCP.


[View source]
def scp_recv(path, &) #

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


[View source]
def scp_recv_file(path, local_path = path) #

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


[View source]
def scp_send(path, mode, size, mtime, atime) #

Send a file to the remote host via SCP.


[View source]
def 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.


[View source]
def scp_send_file(path, remote_path = path) #

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


[View source]
def 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.


[View source]
def set_enable_compression(value) #

ameba:disable Naming/AccessorMethodName

DEPRECATED Use #enable_compression= instead


[View source]
def set_enable_sigpipe(value) #

ameba:disable Naming/AccessorMethodName

DEPRECATED Use #enable_sigpipe= instead


[View source]
def 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.


[View source]
def sftp_session #

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


[View source]
def sftp_session(&) #

[View source]
def socket : TCPSocket #

[View source]
def supported_algs(method_type : LibSSH2::MethodType) #

Get a list of supported algorithms for the given method_type.


[View source]
def 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


[View source]
def 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.


[View source]
def to_unsafe : Pointer(Void) #

[View source]
def trace(bitmask : LibSSH2::Trace) #

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


[View source]