class

SSH2::Channel

Inherits IO / Reference / Object

Constants

PROCESS_EXEC = "exec"
PROCESS_SHELL = "shell"
PROCESS_SUBSYSTEM = "subsystem"

Constructors

new(session : SSH2::Session, handle : LibSSH2::Channel, owned : Bool = true)
Source

Instance methods

close(wait = false)

Close an active data channel. In practice this means sending an SSH_MSG_CLOSE packet to the remote host which serves as instruction that no further data will be sent to it. The remote host may still send data back until it sends its own close message in response. To wait for the remote end to close its connection as well, follow this command with wait_closed or pass wait parameter as true.

Source
closed?

Returns true if this IO is closed.

IO defines returns false, but including types may override.

Source
command(command)

Start a specified command

Source
eof?

Check if the remote host has sent an EOF status for the selected stream.

Source
err_stream

Returns the channel's stderr substream as its own IO (StreamIO).

Source
exit_signal

Return a tuple with first field populated with the exit signal (without leading "SIG"), and the second field populated with the error message.

Source
exit_status

Returns the exit code raised by the process running on the remote host at the other end of the named channel. Note that the exit status may not be available if the remote end has not yet set its status to closed.

Source
finalize
Source
flush(stream_id = 0)

Flush channel

Source
flush_all

Flush all substreams

Source
flush_extended_data

Flush all extended data substreams

Source
flush_stderr

Flush stderr

Source
handle_extended_data(ignore_mode : LibSSH2::ExtendedData)

LibSSH2::ExtendedData::NORMAL - Queue extended data for eventual reading LibSSH2::ExtendedData::MERGE - Treat extended data and ordinary data the same. Merge all substreams such that calls to read, will pull from all substreams on a first-in/first-out basis. LibSSH2::ExtendedData::IGNORE - Discard all extended data as it arrives.

Source
process_startup(request, message)

Request a process on the channel. request is one of PROCESS_SHELL, PROCESS_EXEC or PROCESS_SUBSYSTEM; prefer shell, command or subsystem.

Source
read(stream_id, slice : Slice(UInt8))

Read up to slice.bytesize bytes from substream stream_id into slice, returning the number of bytes read.

Source
read(slice : Slice(UInt8)) : Int32

IO#read: reads from the main (stdout) substream into slice, returning the number of bytes read, or 0 at end-of-file.

Source
read_stderr(slice : Slice(UInt8))

Read from the channel's stderr substream into slice.

Source
receive_window_adjust(adjustment, force = false)

Adjust the receive window for a channel by adjustment bytes. If the amount to be adjusted is less than LibSSH2::CHANNEL_MINADJUST and force is false the adjustment amount will be queued for a later packet. Returns a new size of the receive window (as understood by remote end).

Source
request_pty(term, modes : Array(Tuple(TerminalMode, UInt32)) | Nil = nil, width = LibSSH2::TERM_WIDTH, height = LibSSH2::TERM_HEIGHT, width_px = LibSSH2::TERM_WIDTH_PX, height_px = LibSSH2::TERM_HEIGHT_PX)

Request a PTY on an established channel. Note that this does not make sense for all channel types and may be ignored by the server despite returning success.

Source
send_eof(wait = false)

Tell the remote host that no further data will be sent on the specified channel. Processes typically interpret this as a closed stdin descriptor.

Source
session
Source
setenv(varname, value)

Set an environment variable in the remote channel's process space. Note that this does not make sense for all channel types and may be ignored by the server despite returning success.

Source
shell

Start shell

Source
socket
Source
stream(stream_id)

Returns substream stream_id as its own IO (StreamIO).

Source
subsystem(subsystem)

Start a specified subsystem

Source
to_unsafe
Source
wait_closed

Wait for the remote end to acknowledge the channel close.

Source
wait_eof

Wait for the remote end to acknowledge an EOF request.

Source
window_read

The number of bytes which the remote end may send without overflowing the window limit

Source
window_write

Check the status of the write window Returns the number of bytes which may be safely written on the channel without blocking.

Source
write(stream_id, slice : Slice(UInt8))

Write all of slice to substream stream_id, returning the number of bytes written.

channel_write can write less than we asked. loop until slice is done. n == 0 is allowed by libssh2 (buffered, not acked). yield so we don't spin.

Source
write(slice : Bytes) : Nil

Writes the contents of slice into this IO.

io = IO::Memory.new
slice = Bytes.new(4) { |i| ('a'.ord + i).to_u8 }
io.write(slice)
io.to_s # => "abcd"
Source
write_stderr(slice : Slice(UInt8))

Write slice to the channel's stderr substream.

Source

Nested types