Struct ssh2::Session
[−]
[src]
pub struct Session { /* fields omitted */ }
An SSH session, typically representing one TCP connection.
All other structures are based on an SSH session and cannot outlive a
session. Sessions are created and then have the TCP socket handed to them
(via the handshake
method).
Methods
impl Session
[src]
pub fn new() -> Option<Session>
[src]
Initializes an SSH session object.
This function does not associate the session with a remote connection
just yet. Various configuration options can be set such as the blocking
mode, compression, sigpipe, the banner, etc. To associate this session
with a TCP connection, use the handshake
method to pass in an
already-established TCP socket.
[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]
&self,
username: &str,
password: &str
) -> Result<(), Error>
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]
&self,
username: &str,
pubkey: Option<&Path>,
privatekey: &Path,
passphrase: Option<&str>
) -> Result<(), Error>
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]
&self,
username: &str,
pubkeydata: Option<&str>,
privatekeydata: &str,
passphrase: Option<&str>
) -> Result<(), Error>
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]
&self,
username: &str,
publickey: &Path,
privatekey: &Path,
passphrase: Option<&str>,
hostname: &str,
local_username: Option<&str>
) -> Result<(), Error>
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]
&self,
method_type: MethodType,
prefs: &str
) -> Result<(), Error>
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]
&self,
method_type: MethodType
) -> Result<Vec<&'static str>, Error>
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]
&self,
host: &str,
port: u16,
src: Option<(&str, u16)>
) -> Result<Channel, Error>
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]
&self,
remote_port: u16,
host: Option<&str>,
queue_maxsize: Option<u32>
) -> Result<(Listener, u16), Error>
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]
&self,
remote_path: &Path,
mode: i32,
size: u64,
times: Option<(u64, u64)>
) -> Result<Channel, Error>
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]
&self,
channel_type: &str,
window_size: u32,
packet_size: u32,
message: Option<&str>
) -> Result<Channel, Error>
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
.
[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]
&self,
reason: Option<DisconnectCode>,
description: &str,
lang: Option<&str>
) -> Result<(), Error>
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: c_int) -> Result<(), Error>
[src]
Translate a return code into a Rust-Result
.