[][src]Struct tsunami::Session

pub struct Session { /* fields omitted */ }

An established SSH session.

See ssh2::Session in general, and ssh2::Session#channel_session specifically, for how to execute commands on the remote host.

To execute a command and get its STDOUT output, use Session#cmd.

Methods

impl Session[src]

pub fn cmd_raw(&self, cmd: &str) -> Result<Vec<u8>, Error>[src]

Issue the given command and return the command's raw standard output.

pub fn cmd(&self, cmd: &str) -> Result<String, Error>[src]

Issue the given command and return the command's standard output.

Methods from Deref<Target = Session>

pub fn set_banner(&self, banner: &str) -> Result<(), Error>[src]

Set the SSH protocol banner for the local client

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.

pub fn set_allow_sigpipe(&self, block: bool)[src]

Flag indicating whether SIGPIPE signals will be allowed or blocked.

By default (on relevant platforms) this library will attempt to block and catch SIGPIPE signals. Setting this flag to true will cause the library to not attempt to block SIGPIPE from the underlying socket layer.

pub fn set_compress(&self, compress: bool)[src]

Flag indicating whether this library will attempt to negotiate compression.

If set - before the connection negotiation is performed - libssh2 will try to negotiate compression enabling for this connection. By default libssh2 will not attempt to use compression.

pub fn set_blocking(&self, blocking: bool)[src]

Set or clear blocking mode on session

This will instantly affect any channels associated with this session. If a read is performed on a session with no data currently available, a blocking session will wait for data to arrive and return what it receives. A non-blocking session will return immediately with an empty buffer. If a write is performed on a session with no room for more data, a blocking session will wait for room. A non-blocking session will return immediately without writing anything.

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

Returns whether the session was previously set to nonblocking.

pub fn set_timeout(&self, timeout_ms: u32)[src]

Set timeout for blocking functions.

Set the timeout in milliseconds for how long a blocking the libssh2 function calls may wait until they consider the situation an error and return an error.

By default or if you set the timeout to zero, libssh2 has no timeout for blocking functions.

pub fn timeout(&self) -> u32[src]

Returns the timeout, in milliseconds, for how long blocking calls may wait until they time out.

A timeout of 0 signifies no timeout.

pub fn handshake(&mut self, stream: &TcpStream) -> Result<(), Error>[src]

Begin transport layer protocol negotiation with the connected host.

This session does not take ownership of the socket provided, it is recommended to ensure that the socket persists the lifetime of this session to ensure that communication is correctly performed.

It is also highly recommended that the stream provided is not used concurrently elsewhere for the duration of this session as it may interfere with the protocol.

pub fn userauth_password(
    &self,
    username: &str,
    password: &str
) -> Result<(), Error>
[src]

Attempt basic password authentication.

Note that many SSH servers which appear to support ordinary password authentication actually have it disabled and use Keyboard Interactive authentication (routed via PAM or another authentication backed) instead.

pub fn userauth_agent(&self, username: &str) -> Result<(), Error>[src]

Attempt to perform SSH agent authentication.

This is a helper method for attempting to authenticate the current connection with the first public key found in an SSH agent. If more control is needed than this method offers, it is recommended to use agent directly to control how the identity is found.

pub fn userauth_pubkey_file(
    &self,
    username: &str,
    pubkey: Option<&Path>,
    privatekey: &Path,
    passphrase: Option<&str>
) -> Result<(), Error>
[src]

Attempt public key authentication using a PEM encoded private key file stored on disk.

pub fn userauth_pubkey_memory(
    &self,
    username: &str,
    pubkeydata: Option<&str>,
    privatekeydata: &str,
    passphrase: Option<&str>
) -> Result<(), Error>
[src]

Attempt public key authentication using a PEM encoded private key from memory. Public key is computed from private key if none passed. This is available only for unix targets, as it relies on openssl. It is therefore recommended to use #[cfg(unix)] or otherwise test for the unix compliation target when using this function.

pub fn userauth_hostbased_file(
    &self,
    username: &str,
    publickey: &Path,
    privatekey: &Path,
    passphrase: Option<&str>,
    hostname: &str,
    local_username: Option<&str>
) -> Result<(), Error>
[src]

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

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

pub fn auth_methods(&self, username: &str) -> Result<&str, Error>[src]

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 an error. This case may be distinguished from a failing case by examining the return value of the authenticated method.

The return value is a comma-separated string of supported auth schemes.

pub fn method_pref(
    &self,
    method_type: MethodType,
    prefs: &str
) -> Result<(), Error>
[src]

Set preferred key exchange method

The preferences provided are a comma delimited list of preferred methods to use with the most preferred listed first and the least preferred listed last. If a method is listed which is not supported by libssh2 it will be ignored and not sent to the remote host during protocol negotiation.

pub fn methods(&self, method_type: MethodType) -> Option<&str>[src]

Return the currently active algorithms.

Returns the actual method negotiated for a particular transport parameter. May return None if the session has not yet been started.

pub fn supported_algs(
    &self,
    method_type: MethodType
) -> Result<Vec<&'static str>, Error>
[src]

Get list of supported algorithms.

pub fn agent(&self) -> Result<Agent, Error>[src]

Init an ssh-agent handle.

The returned agent will still need to be connected manually before use.

pub fn known_hosts(&self) -> Result<KnownHosts, Error>[src]

Init a collection of known hosts for this session.

Returns the handle to an internal representation of a known host collection.

pub fn channel_session(&self) -> Result<Channel, Error>[src]

Establish a new session-based channel.

This method is commonly used to create a channel to execute commands over or create a new login shell.

pub fn channel_direct_tcpip(
    &self,
    host: &str,
    port: u16,
    src: Option<(&str, u16)>
) -> Result<Channel, Error>
[src]

Tunnel a TCP connection through an SSH session.

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.

The optional src argument is the host/port to tell the SSH server where the connection originated from.

The Channel returned represents a connection between this host and the specified remote host.

pub fn channel_forward_listen(
    &self,
    remote_port: u16,
    host: Option<&str>,
    queue_maxsize: Option<u32>
) -> Result<(Listener, u16), Error>
[src]

Instruct the remote SSH server to begin listening for inbound TCP/IP connections.

New connections will be queued by the library until accepted by the accept method on the returned Listener.

pub fn scp_recv(&self, path: &Path) -> Result<(Channel, ScpFileStat), Error>[src]

Request a file from the remote host via SCP.

The path specified is a path on the remote host which will attempt to be sent over the returned channel. Some stat information is also returned about the remote file to prepare for receiving the file.

pub fn scp_send(
    &self,
    remote_path: &Path,
    mode: i32,
    size: u64,
    times: Option<(u64, u64)>
) -> Result<Channel, Error>
[src]

Send a file to the remote host via SCP.

The remote_path provided will the remote file name. The times argument is a tuple of (mtime, atime), and will default to the remote host's current time if not specified.

The size of the file, size, must be known ahead of time before transmission.

pub fn sftp(&self) -> Result<Sftp, Error>[src]

Open a channel and initialize the SFTP subsystem.

Although the SFTP subsystem operates over the same type of channel as those exported by the Channel API, the protocol itself implements its own unique binary packet protocol which must be managed with the methods on Sftp.

pub fn channel_open(
    &self,
    channel_type: &str,
    window_size: u32,
    packet_size: u32,
    message: Option<&str>
) -> Result<Channel, Error>
[src]

Allocate a new channel for exchanging data with the server.

This is typically not called directly but rather through channel_session, channel_direct_tcpip, or channel_forward_listen.

pub fn banner(&self) -> Option<&str>[src]

Get the remote 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.

May return None on invalid utf-8 or if an error has ocurred.

[src]

See banner.

Will only return None if an error has ocurred.

pub fn host_key(&self) -> Option<(&[u8], HostKeyType)>[src]

Get the remote key.

Returns None if something went wrong.

pub fn host_key_hash(&self, hash: HashType) -> Option<&[u8]>[src]

Returns the computed digest of the remote system's hostkey.

The bytes returned are the raw hash, and are not printable. If the hash is not yet available None is returned.

pub fn set_keepalive(&self, want_reply: bool, interval: u32)[src]

Set how often keepalive messages should be sent.

The want_reply argument indicates whether the keepalive messages should request a response from the server.

The interval argument is number of seconds that can pass without any I/O, use 0 (the default) to disable keepalives. To avoid some busy-loop corner-cases, if you specify an interval of 1 it will be treated as 2.

pub fn keepalive_send(&self) -> Result<u32, Error>[src]

Send a keepalive message if needed.

Returns how many seconds you can sleep after this call before you need to call it again.

pub fn disconnect(
    &self,
    reason: Option<DisconnectCode>,
    description: &str,
    lang: Option<&str>
) -> Result<(), Error>
[src]

Terminate the transport layer.

Send a disconnect message to the remote host associated with session, along with a reason symbol and a verbose description.

Note that this does not close the underlying socket.

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

Translate a return code into a Rust-Result.

Trait Implementations

impl DerefMut for Session[src]

impl Deref for Session[src]

type Target = Session

The resulting type after dereferencing.

Auto Trait Implementations

impl !Sync for Session

impl Send for Session

impl Unpin for Session

impl RefUnwindSafe for Session

impl UnwindSafe for Session

Blanket Implementations

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

impl<T, U> Into<U> for T where
    U: From<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]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> Erased for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> SendSyncUnwindSafe for T where
    T: Send + Sync + UnwindSafe + ?Sized
[src]