class SSH2::Session
- SSH2::Session
- Reference
- Object
Defined in:
session.crConstant 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
-
#authenticated?
Indicates whether or not the named session has been successfully authenticated.
-
#banner
Once the session has been setup and
#handshake
has completed successfully, this function can be used to get the server id from the banner each server presents. -
#banner=(value)
Set the banner that will be sent to the remote host when the SSH session is started with
#handshake
. -
#block_directions
Returns block direction flags
-
#blocking?
check whether the session is in blocking mode
-
#direct_streamlocal(path, host, port)
Tunnel TCP/IP connect through the SSH session to direct UNIX socket.
- #direct_streamlocal(path, host, port, &)
-
#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.
- #direct_tcpip(host, port, source_host, source_port, &)
-
#disconnect(reason = LibSSH2::DisconnectReason::BY_APPLICATION, description = "bye")
Send a disconnect message to the remote host associated with session, along with a description.
- #enable_compression=(value)
- #enable_sigpipe=(value)
- #finalize
-
#forward_listen(host, port, queue_maxsize = 16)
Instruct the remote SSH server to begin listening for inbound TCP/IP connections.
-
#handshake
Begin transport layer protocol negotiation with the connected host.
-
#hashkey(type : LibSSH2::HashType = LibSSH2::HashType::SHA256)
Returns the current session's host key
-
#hostkey
Returns a tuple consisting of the computed digest of the remote system's hostkey and its type.
-
#interactive_login(username, &callback : Proc(String, String, String))
Login with an interactive password
-
#knownhosts
Return
KnownHosts
object that allows managing known hosts -
#login(username : String, password : String)
Login with username and password
-
#login_with_agent(username : String)
Login with username using SSH agent Warning: this method will block the crystal lang event loop.
-
#login_with_data(username : String, privkey : String, pubkey : String, passphrase : String | Nil = nil)
Login with username using pub/priv key values
-
#login_with_noauth(username : String)
Send a SSH_USERAUTH_NONE request to the remote host.
-
#login_with_pubkey(username : String, privkey : String, pubkey : String, passphrase : String | Nil = nil)
Login with username using pub/priv key files
-
#method_pref(method_pref : LibSSH2::MethodType)
Returns the actual method negotiated for a particular transport parameter.
- #nonblock_handle(&)
-
#open_channel(channel_type, window_size, packet_size, message)
Allocate a new channel for exchanging data with the server.
-
#open_session
Open new session channel
- #open_session(&)
- #perform_nonblock(&)
-
#scp_recv(path)
Request a file from the remote host via SCP.
-
#scp_recv(path, &)
Request a file from the remote host via SCP.
-
#scp_recv_file(path, local_path = path)
Download a file from the remote host via SCP to the local filesystem.
-
#scp_send(path, mode, size, mtime, atime)
Send a file to the remote host via SCP.
-
#scp_send(path, mode, size, mtime = Time.utc.to_unix, atime = Time.utc.to_unix, &)
Send a file to the remote host via SCP.
-
#scp_send_file(path, remote_path = path)
Send a file from a local filesystem to the remote host via SCP.
-
#send_keepalive
Send a keepalive message if needed.
-
#set_enable_compression(value)
ameba:disable Naming/AccessorMethodName
DEPRECATED Use
#enable_compression=
instead -
#set_enable_sigpipe(value)
ameba:disable Naming/AccessorMethodName
DEPRECATED Use
#enable_sigpipe=
instead -
#set_method_pref(method_type : LibSSH2::MethodType, value)
Set preferred methods to be negotiated.
-
#sftp_session
Open a channel and initialize the SFTP subsystem.
- #sftp_session(&)
- #socket : TCPSocket
-
#supported_algs(method_type : LibSSH2::MethodType)
Get a list of supported algorithms for the given method_type.
-
#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
-
#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.
- #to_unsafe : Pointer(Void)
-
#trace(bitmask : LibSSH2::Trace)
Set the trace option.
Constructor Detail
Class Method Detail
Instance Method Detail
Indicates whether or not the named session has been successfully authenticated.
Once the session has been setup and #handshake
has completed successfully,
this function can be used to get the server id from the banner each server
presents.
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.
Tunnel TCP/IP connect through the SSH session to direct UNIX socket.
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.
Send a disconnect message to the remote host associated with session, along with a description.
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
.
Returns the current session's host key
Returns a tuple consisting of the computed digest of the remote system's hostkey and its type.
Login with an interactive password
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.
Login with username using pub/priv key values
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
Login with username using pub/priv key files
Returns the actual method negotiated for a particular transport parameter.
Allocate a new channel for exchanging data with the server.
Request a file from the remote host via SCP. A new channel is passed to the block and closed afterwards.
Download a file from the remote host via SCP to the local filesystem.
Send a file to the remote host via SCP. A new channel is passed to the block and closed afterwards.
Send a file from a local filesystem to the remote host via SCP.
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.
ameba:disable Naming/AccessorMethodName
DEPRECATED Use #enable_compression=
instead
ameba:disable Naming/AccessorMethodName
DEPRECATED Use #enable_sigpipe=
instead
Set preferred methods to be negotiated. These preferences must be set prior
to calling #handshake
, as they are used during the protocol initiation
phase.
Get a list of supported algorithms for the given method_type.
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
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.
Set the trace option. Only available if libssh2 is compliled with debug mode.