remotefs SSH

March 20, 2026 ยท View on GitHub

license-mit repo-stars downloads latest-version ko-fi conventional-commits

Build coveralls docs


About remotefs-ssh โ˜๏ธ

remotefs-ssh is a client implementation for remotefs, providing support for the SFTP/SCP protocol.


Get started ๐Ÿš€

First of all, add remotefs-ssh to your project dependencies:

remotefs = "0.3"
remotefs-ssh = "0.8"

Note

The library supports multiple ssh backends. Currently libssh2, libssh, and russh are 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 the libssh2 library for SSH connections.
  • libssh: An alternative backend, using the libssh library for SSH connections.
  • russh: A pure-Rust backend, using the russh library 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:

  • libssh2-vendored: Build the libssh2 backend with the vendored version of the library.
  • libssh-vendored: Build the libssh backend 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.

Note

If you need SftpFs to be Sync YOU MUST use libssh2 or russh. The libssh backend does not support Sync.

Other features

these features are supported:

  • find: enable find() method on client (enabled by default)
  • no-log: disable logging. By default, this library will log via the log crate.

Ssh client

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 example

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 example

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());

Client compatibility table โœ”๏ธ

The following table states the compatibility for the client client and the remote file system trait method.

Note: connect(), disconnect() and is_connected() MUST always be supported, and are so omitted in the table.

Client/MethodScpSftp
append_fileNoYes
appendNoYes
change_dirYesYes
copyYesYes
create_dirYesYes
create_fileYesYes
createYesYes
execYesYes
existsYesYes
list_dirYesYes
movYesYes
open_fileYesYes
openYesYes
pwdYesYes
remove_dir_allYesYes
remove_dirYesYes
remove_fileYesYes
setstatYesYes
statYesYes
symlinkYesYes

Support the developer โ˜•

If you like remotefs-ssh and you're grateful for the work I've done, please consider a little donation ๐Ÿฅณ

You can make a donation with one of these platforms:

ko-fi PayPal bitcoin


Contributing and issues ๐Ÿค๐Ÿป

Contributions, bug reports, new features, and questions are welcome! ๐Ÿ˜‰ If you have any questions or concerns, or you want to suggest a new feature, or you want just want to improve remotefs, feel free to open an issue or a PR.

Please follow our contributing guidelines


Changelog โณ

View remotefs-ssh changelog HERE


Powered by ๐Ÿ’ช

remotefs-ssh is powered by these awesome projects:


License ๐Ÿ“ƒ

remotefs-ssh is licensed under the MIT license.

You can read the entire license HERE