class SSH2::Channel

Defined in:

channel.cr

Constant Summary

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

Constructors

Instance Method Summary

Constructor Detail

def self.new(session : SSH2::Session, handle : LibSSH2::Channel, owned : Bool = true) #

[View source]

Instance Method Detail

def 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.


[View source]
def closed? : Bool #
Description copied from class IO

Returns true if this IO is closed.

IO defines returns false, but including types may override.


[View source]
def command(command) #

Start a specified command


[View source]
def eof? #

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


[View source]
def err_stream #

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


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


[View source]
def finalize #

[View source]
def flush(stream_id = 0) #

Flush channel


[View source]
def flush_all #

Flush all substreams


[View source]
def flush_extended_data #

Flush all extended data substreams


[View source]
def flush_stderr #

Flush stderr


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


[View source]
def process_startup(request, message) #

[View source]
def read(stream_id, slice : Slice(UInt8)) #

[View source]
def read(slice : Slice(UInt8)) #
Description copied from class IO

Reads at most slice.size bytes from this IO into slice. Returns the number of bytes read, which is 0 if and only if there is no more data to read (so checking for 0 is the way to detect end of file).

io = IO::Memory.new "hello"
slice = Bytes.new(4)
io.read(slice) # => 4
slice          # => Bytes[104, 101, 108, 108]
io.read(slice) # => 1
slice          # => Bytes[111, 101, 108, 108]
io.read(slice) # => 0

[View source]
def read_stderr(slice : Slice(UInt8)) #

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


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


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


[View source]
def session : Session #

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


[View source]
def shell #

Start shell


[View source]
def socket #

[View source]
def stream(stream_id) #

[View source]
def subsystem(subsystem) #

Start a specified subsystem


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

[View source]
def wait_closed #

[View source]
def wait_eof #

Wait for the remote end to acknowledge an EOF request.


[View source]
def window_read #

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


[View source]
def window_write #

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


[View source]
def write(stream_id, slice : Slice(UInt8)) #

[View source]
def write(slice : Bytes) : Nil #
Description copied from class IO

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"

[View source]
def write_stderr(slice : Slice(UInt8)) #

[View source]