[][src]Struct ssh2::Channel

pub struct Channel { /* fields omitted */ }

A channel represents a portion of an SSH connection on which data can be read and written.

Channels denote all of SCP uploads and downloads, shell sessions, remote process executions, and other general-purpose sessions. Each channel implements the Reader and Writer traits to send and receive data. Whether or not I/O operations are blocking is mandated by the blocking flag on a channel's corresponding Session.

Methods

impl Channel[src]

pub fn setenv(&mut self, var: &str, val: &str) -> Result<(), Error>[src]

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.

pub fn request_pty(
    &mut self,
    term: &str,
    mode: Option<&str>,
    dim: Option<(u32, u32, u32, u32)>
) -> Result<(), Error>
[src]

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.

The dimensions argument is a tuple of (width, height, width_px, height_px)

pub fn request_pty_size(
    &mut self,
    width: u32,
    height: u32,
    width_px: Option<u32>,
    height_px: Option<u32>
) -> Result<(), Error>
[src]

Request a PTY of a specified size

pub fn exec(&mut self, command: &str) -> Result<(), Error>[src]

Execute a command

An execution is one of the standard process services defined by the SSH2 protocol.

Example

let mut channel = session.channel_session().unwrap();
channel.exec("ls").unwrap();
let mut s = String::new();
channel.read_to_string(&mut s).unwrap();
println!("{}", s);

pub fn shell(&mut self) -> Result<(), Error>[src]

Start a shell

A shell is one of the standard process services defined by the SSH2 protocol.

pub fn subsystem(&mut self, system: &str) -> Result<(), Error>[src]

Request a subsystem be started.

A subsystem is one of the standard process services defined by the SSH2 protocol.

pub fn process_startup(
    &mut self,
    request: &str,
    message: Option<&str>
) -> Result<(), Error>
[src]

Initiate a request on a session type channel.

The SSH2 protocol currently defines shell, exec, and subsystem as standard process services.

Important traits for Stream<'channel>
pub fn stderr<'a>(&'a mut self) -> Stream<'a>[src]

Get a handle to the stderr stream of this channel.

The returned handle implements the Read and Write traits.

Important traits for Stream<'channel>
pub fn stream<'a>(&'a mut self, stream_id: i32) -> Stream<'a>[src]

Get a handle to a particular stream for this channel.

The returned handle implements the Read and Write traits.

Groups of substreams may be flushed by passing on of the following constants and then calling flush().

  • FLUSH_EXTENDED_DATA - Flush all extended data substreams
  • FLUSH_ALL - Flush all substreams

pub fn handle_extended_data(&mut self, mode: ExtendedData) -> Result<(), Error>[src]

Change how extended data (such as stderr) is handled

pub fn exit_status(&self) -> Result<i32, Error>[src]

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.

pub fn exit_signal(&self) -> Result<ExitSignal, Error>[src]

Get the remote exit signal.

pub fn read_window(&self) -> ReadWindow[src]

Check the status of the read window.

pub fn write_window(&self) -> WriteWindow[src]

Check the status of the write window.

pub fn adjust_receive_window(
    &mut self,
    adjust: u64,
    force: bool
) -> Result<u64, Error>
[src]

Adjust the receive window for a channel by adjustment bytes.

If the amount to be adjusted is less than the minimum adjustment and force is false, the adjustment amount will be queued for a later packet.

This function returns the new size of the receive window (as understood by remote end) on success.

pub fn eof(&self) -> bool[src]

Check if the remote host has sent an EOF status for the channel. Take care: the EOF status is for the entire channel which can be confusing because the reading from the channel reads only the stdout stream. unread, buffered, stderr data will cause eof() to return false.

pub fn send_eof(&mut self) -> Result<(), Error>[src]

Tell the remote host that no further data will be sent on the specified channel.

Processes typically interpret this as a closed stdin descriptor.

pub fn wait_eof(&mut self) -> Result<(), Error>[src]

Wait for the remote end to send EOF. Note that unread buffered stdout and stderr will cause this function to return Ok(()) without waiting. You should call the eof() function after calling this to check the status of the channel.

pub fn close(&mut self) -> Result<(), Error>[src]

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

pub fn wait_close(&mut self) -> Result<(), Error>[src]

Enter a temporary blocking state until the remote host closes the named channel.

Typically sent after close in order to examine the exit status.

Trait Implementations

impl Drop for Channel[src]

impl Read for Channel[src]

fn read_vectored(&mut self, bufs: &mut [IoSliceMut]) -> Result<usize, Error>1.36.0[src]

Like read, except that it reads into a slice of buffers. Read more

unsafe fn initializer(&self) -> Initializer[src]

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>1.0.0[src]

Read all bytes until EOF in this source, placing them into buf. Read more

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>1.0.0[src]

Read all bytes until EOF in this source, appending them to buf. Read more

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>1.6.0[src]

Read the exact number of bytes required to fill buf. Read more

fn by_ref(&mut self) -> &mut Self1.0.0[src]

Creates a "by reference" adaptor for this instance of Read. Read more

fn bytes(self) -> Bytes<Self>1.0.0[src]

Transforms this Read instance to an [Iterator] over its bytes. Read more

fn chain<R>(self, next: R) -> Chain<Self, R> where
    R: Read
1.0.0[src]

Creates an adaptor which will chain this stream with another. Read more

fn take(self, limit: u64) -> Take<Self>1.0.0[src]

Creates an adaptor which will read at most limit bytes from it. Read more

impl Write for Channel[src]

fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize, Error>1.36.0[src]

Like write, except that it writes from a slice of buffers. Read more

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>1.0.0[src]

Attempts to write an entire buffer into this writer. Read more

fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>1.0.0[src]

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self1.0.0[src]

Creates a "by reference" adaptor for this instance of Write. Read more

Auto Trait Implementations

impl Unpin for Channel

impl !Send for Channel

impl !Sync for Channel

impl !UnwindSafe for Channel

impl !RefUnwindSafe for Channel

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]