Skip to content

Commit e749d8b

Browse files
authored
feat!: Support for multiple SSH backends. Support for libssh.org (#10)
* feat!: Support for multiple SSH backends. Support for libssh.org Added new feature to enable **libssh2** backend; Added a new feature to enable **libssh** backend. Renamed ssh2-vendored feature to libssh2-vendored. Removed `new`; use `libssh2` and `libssh` constructors instead. By default libssh2 feature is enabled. See README for more details BREAKING CHANGE: Removed `From<SshOpts>`; Removed `new`; use `libssh2` and `libssh` constructors instead; Renamed ssh2-vendored feature to libssh2-vendored * fix: Benchmarks for libssh2 * feat: libssh backend * test: Added libssh tests * fix: Restore From for SshOpts into SftpFs/ScpFs * fix: broken code for libssh backende * style: lint
1 parent 9b5e1d9 commit e749d8b

File tree

26 files changed

+6965
-2788
lines changed

26 files changed

+6965
-2788
lines changed

.cargo/config.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[alias]
2+
lint = "clippy --features libssh,libssh2 -- -Dwarnings"
3+
test-all = "test --features libssh,libssh2"
4+
test-libssh = "test --no-default-features --features libssh"
5+
test-libssh2 = "test --features libssh2"

.github/workflows/linux.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: test
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
CARGO_TERM_COLOR: always
7+
8+
jobs:
9+
test:
10+
name: Test (${{ matrix.features }})
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
features: [libssh, libssh2]
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v2
19+
20+
- name: Setup rust toolchain
21+
uses: dtolnay/rust-toolchain@stable
22+
with:
23+
toolchain: stable
24+
25+
- uses: taiki-e/install-action@v2
26+
with:
27+
tool: cargo-llvm-cov
28+
29+
- name: Clippy
30+
run: cargo clippy --features ${{ matrix.features }} -- -Dwarnings
31+
32+
- name: Run tests with coverage
33+
run: cargo llvm-cov --no-fail-fast --features ${{ matrix.features }} --workspace --lcov --output-path lcov-${{ matrix.features }}.info
34+
35+
- name: Upload to Coveralls
36+
uses: coverallsapp/[email protected]
37+
with:
38+
github-token: ${{ secrets.GITHUB_TOKEN }}
39+
parallel: true
40+
file: lcov-${{ matrix.features }}.info
41+
42+
wait-for-coverage:
43+
name: Wait for coverage
44+
runs-on: ubuntu-latest
45+
needs: test
46+
steps:
47+
- name: Wait for coveralls
48+
uses: coverallsapp/[email protected]
49+
with:
50+
github-token: ${{ secrets.GITHUB_TOKEN }}
51+
parallel-finished: true

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
- [Changelog](#changelog)
4+
- [0.7.0](#070)
45
- [0.6.4](#064)
56
- [0.6.3](#063)
67
- [0.6.2](#062)
@@ -22,6 +23,19 @@
2223

2324
---
2425

26+
## 0.7.0
27+
28+
Released on 16/08/2025
29+
30+
- **BREAKING**: Support for multiple SSH backends:
31+
- Added new feature to enable **libssh2** backend:
32+
- Use `libssh2` feature to enable the backend
33+
- Use `libssh2-vendored` to build the backend with vendored libssh2
34+
- Added support for [libssh](https://www.libssh.org/) backend
35+
- Use `libssh` feature to enable the backend
36+
- Use `libssh-vendored` to build the backend with vendored libssh
37+
- Removed `new`; use `libssh2` and `libssh` constructors instead.
38+
2539
## 0.6.4
2640

2741
Released on 15/08/2025

Cargo.toml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,49 @@ license = "MIT"
1010
name = "remotefs-ssh"
1111
readme = "README.md"
1212
repository = "https://github.com/remotefs-rs/remotefs-rs-ssh"
13-
version = "0.6.4"
13+
version = "0.7.0"
1414
rust-version = "1.85.1"
1515

1616
[dependencies]
1717
chrono = "^0.4"
1818
lazy-regex = "3"
19+
libssh-rs = { version = "0.3", optional = true }
1920
log = "^0.4"
2021
remotefs = "^0.3"
2122
ssh2-config = "^0.6"
22-
ssh2 = "^0.9"
23+
ssh2 = { version = "^0.9", optional = true }
2324

2425
[dev-dependencies]
26+
criterion = "0.7"
2527
env_logger = "^0.11"
2628
pretty_assertions = "^1"
2729
rand = "^0.9"
2830
tempfile = "^3"
2931
testcontainers = { version = "0.25", features = ["blocking"] }
3032

3133
[features]
32-
default = ["find"]
33-
# misc
34+
default = ["find", "libssh2"]
3435
find = ["remotefs/find"]
36+
libssh = ["dep:libssh-rs"]
37+
libssh-vendored = ["libssh", "libssh-rs/vendored", "libssh-rs/vendored-openssl"]
38+
libssh2 = ["dep:ssh2"]
39+
libssh2-vendored = ["libssh2", "ssh2/vendored-openssl"]
3540
no-log = ["log/max_level_off"]
36-
ssh2-vendored = ["ssh2/vendored-openssl"]
37-
# tests
38-
github-actions = []
3941

4042
[target."cfg(target_os = \"windows\")"]
4143
[target."cfg(target_os = \"windows\")".dependencies]
4244
path-slash = "^0.2.1"
45+
46+
[package.metadata.docs.rs]
47+
all-features = true
48+
rustdoc-args = ["--cfg", "docsrs"]
49+
50+
[[bench]]
51+
name = "libssh2"
52+
harness = false
53+
required-features = ["libssh2"]
54+
55+
[[bench]]
56+
name = "libssh"
57+
harness = false
58+
required-features = ["libssh"]

README.md

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
<p align="center">~ Remotefs SSH client ~</p>
1212

13-
<p align="center">Developed by <a href="https://veeso.github.io/" target="_blank">@veeso</a></p>
14-
<p align="center">Current version: 0.6.4 (15/08/2025)</p>
13+
<p align="center">Developed by <a href="https://veeso.me/" target="_blank">@veeso</a></p>
14+
<p align="center">Current version: 0.7.0 (16/08/2025)</p>
1515

1616
<p align="center">
1717
<a href="https://opensource.org/licenses/MIT"
@@ -41,9 +41,9 @@
4141
/></a>
4242
</p>
4343
<p align="center">
44-
<a href="https://github.com/remotefs-rs/remotefs-rs-ssh/actions"
44+
<a href="https://github.com/remotefs-rs/remotefs-rs-ssh/actions/workflows/linux.yml"
4545
><img
46-
src="https://github.com/remotefs-rs/remotefs-rs-ssh/workflows/Linux/badge.svg"
46+
src="https://github.com/remotefs-rs/remotefs-rs-ssh/actions/workflows/test.yml/badge.svg"
4747
alt="Linux CI"
4848
/></a>
4949
<a href="https://coveralls.io/github/remotefs-rs/remotefs-rs-ssh"
@@ -72,14 +72,68 @@ First of all, add `remotefs-ssh` to your project dependencies:
7272

7373
```toml
7474
remotefs = "0.3"
75-
remotefs-ssh = "^0.6"
75+
remotefs-ssh = "^0.7"
7676
```
7777

78+
> ![NOTE]
79+
> The library supports multiple ssh backends.
80+
> Currently `libssh2` and `libssh` are supported.
81+
>
82+
> By default the library is using `libssh2`.
83+
84+
### Available backends
85+
86+
Each backend can be set as a feature in your `Cargo.toml`. Multiple backends can be enabled at the same time.
87+
88+
- `libssh`: An alternative backend, using the `libssh` library for SSH connections.
89+
- `libssh2`: The default backend, using the `libssh2` library for SSH connections.
90+
91+
Each backend can be built with the vendored version, using the vendored feature instead:
92+
93+
- `libssh-vendored`: Build the `libssh` backend with the vendored version of the library.
94+
- `libssh2-vendored`: Build the `libssh2` backend with the vendored version of the library.
95+
96+
If the vendored feature is **NOT** provided, you will need to have the corresponding system libraries installed on your machine.
97+
98+
> ![NOTE]
99+
> If you need SftpFs to be `Sync` YOU MUST use libssh2.
100+
101+
### Other features
102+
78103
these features are supported:
79104

80105
- `find`: enable `find()` method on client (*enabled by default*)
81106
- `no-log`: disable logging. By default, this library will log via the `log` crate.
82-
- `ssh2-vendored`: build with static libssl
107+
108+
## Ssh client
109+
110+
Here is a basic usage example, with the `Sftp` client, which is very similiar to the `Scp` client.
111+
112+
Both the `SftpFs` and `ScpFs` constructors are respectively `SftpFs::libssh2` and `SftpFs::libssh` accordingly to the enabled backends.
113+
114+
```rust,ignore
115+
// import remotefs trait and client
116+
use remotefs::RemoteFs;
117+
use remotefs_ssh::{SshConfigParseRule, SftpFs, SshOpts};
118+
use std::path::Path;
119+
120+
let opts = SshOpts::new("127.0.0.1")
121+
.port(22)
122+
.username("test")
123+
.password("password")
124+
.config_file(Path::new("/home/cvisintin/.ssh/config"), ParseRule::STRICT);
125+
126+
let mut client = SftpFs::libssh2(opts);
127+
128+
// connect
129+
assert!(client.connect().is_ok());
130+
// get working directory
131+
println!("Wrkdir: {}", client.pwd().ok().unwrap().display());
132+
// change working directory
133+
assert!(client.change_dir(Path::new("/tmp")).is_ok());
134+
// disconnect
135+
assert!(client.disconnect().is_ok());
136+
```
83137

84138
---
85139

@@ -137,7 +191,7 @@ Please follow [our contributing guidelines](CONTRIBUTING.md)
137191

138192
## Changelog ⏳
139193

140-
View remotefs' changelog [HERE](CHANGELOG.md)
194+
View remotefs-ssh changelog [HERE](CHANGELOG.md)
141195

142196
---
143197

0 commit comments

Comments
 (0)