Expand description
§remotefs-ssh
remotefs-ssh is a client implementation for remotefs, providing support for the SCP/SFTP protocols.
§Get started
First of all you need to add remotefs and the client to your project dependencies:
remotefs = "^0.3"
remotefs-ssh = "^0.8"The library supports multiple ssh backends. Currently
libssh2,libssh, andrusshare supported.By default the library is using
libssh2.
§Available backends
Each backend can be set as a feature in your Cargo.toml. Multiple backends can be enabled at the same time.
libssh2: The default backend, using thelibssh2library for SSH connections.libssh: An alternative backend, using thelibsshlibrary for SSH connections.russh: A pure-Rust backend, using therusshlibrary for SSH connections. Does not require any system C libraries.
Each C backend can be built with the vendored version, using the vendored feature instead:
libssh-vendored: Build thelibsshbackend with the vendored version of the library.libssh2-vendored: Build thelibssh2backend with the vendored version of the library.
If the vendored feature is NOT provided, you will need to have the corresponding system libraries installed on your machine.
If you need SftpFs to be
SyncYOU MUST uselibssh2orrussh. Thelibsshbackend does not supportSync.
§Other features
these features are supported:
find: enablefind()method on client (enabled by default)no-log: disable logging. By default, this library will log via thelogcrate.
§Examples
Here is a basic usage example, with the Sftp client, which is very similiar to the Scp client.
The SftpFs and ScpFs constructors vary depending on the enabled backend:
SftpFs::libssh2, SftpFs::libssh, or SftpFs::russh (and likewise for ScpFs).
§libssh2 / libssh
use remotefs::RemoteFs;
use remotefs_ssh::{SshConfigParseRule, SftpFs, SshOpts};
use std::path::Path;
let opts = SshOpts::new("127.0.0.1")
.port(22)
.username("test")
.password("password")
.config_file(Path::new("/home/cvisintin/.ssh/config"), ParseRule::STRICT);
let mut client = SftpFs::libssh2(opts);
// connect
assert!(client.connect().is_ok());
// get working directory
println!("Wrkdir: {}", client.pwd().ok().unwrap().display());
// change working directory
assert!(client.change_dir(Path::new("/tmp")).is_ok());
// disconnect
assert!(client.disconnect().is_ok());§russh
The russh backend requires a Tokio runtime and a type implementing russh::client::Handler
for server key verification. NoCheckServerKey is provided as a convenience handler that
accepts all host keys.
use remotefs::RemoteFs;
use remotefs_ssh::{NoCheckServerKey, SftpFs, SshOpts};
use std::path::Path;
use std::sync::Arc;
let runtime = Arc::new(
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap(),
);
let opts = SshOpts::new("127.0.0.1")
.port(22)
.username("test")
.password("password");
let mut client: SftpFs<remotefs_ssh::RusshSession<NoCheckServerKey>> =
SftpFs::russh(opts, runtime);
// connect
assert!(client.connect().is_ok());
// get working directory
println!("Wrkdir: {}", client.pwd().ok().unwrap().display());
// change working directory
assert!(client.change_dir(Path::new("/tmp")).is_ok());
// disconnect
assert!(client.disconnect().is_ok());Structs§
- KeyMethod
- Ssh key method.
Defined by
MethodType(see ssh2 docs) and the list of supported algorithms. - LibSsh2
Session libssh2 - An implementation of
SshSessionusing libssh2 as the backend. - LibSsh
Session libssh - An implementation of
SshSessionusing libssh as the backend. - NoCheck
Server Key russh - The default SSH client handler for russh.
- Russh
Session russh russhsession.- ScpFs
- SCP “filesystem” client
- SftpFs
- Sftp “filesystem” client
- SshConfig
Parse Rule - The parsing mode
- SshOpts
- Ssh options; used to build and configure SCP/SFTP client.
Enums§
- Method
Type KeyMethodmethod type for SSH key exchange.- SshAgent
Identity - Ssh agent identity
Traits§
- SshKey
Storage - This trait must be implemented in order to use ssh keys for authentication for sftp/scp.
- SshSession
- SSH session trait.