Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(services/sftp): support copy and read_seek #2267

Merged
merged 4 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ minitrace = { version = "0.4.0", optional = true }
moka = { version = "0.10", optional = true, features = ["future"] }
once_cell = "1"
openssh = { version = "0.9.9", optional = true }
openssh-sftp-client = { version = "0.13.4", optional = true, features = [
openssh-sftp-client = { version = "0.13.5", optional = true, features = [
"openssh",
"tracing",
] }
Expand Down
16 changes: 15 additions & 1 deletion core/src/services/sftp/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use crate::*;
/// - [x] write
/// - [x] create_dir
/// - [x] delete
/// - [ ] copy
/// - [x] copy
/// - [x] rename
/// - [x] list
/// - [ ] ~~scan~~
Expand All @@ -69,6 +69,7 @@ use crate::*;
/// - `user`: Set the login user
/// - `key`: Set the public key for login
/// - `known_hosts_strategy`: Set the strategy for known hosts, default to `Strict`
/// - `enable_copy`: Set whether the remote server has copy-file extension
///
/// It doesn't support password login, you can use public key instead.
///
Expand Down Expand Up @@ -104,6 +105,7 @@ pub struct SftpBuilder {
user: Option<String>,
key: Option<String>,
known_hosts_strategy: Option<String>,
enable_copy: bool,
}

impl Debug for SftpBuilder {
Expand Down Expand Up @@ -174,6 +176,14 @@ impl SftpBuilder {

self
}

/// set enable_copy for sftp backend.
/// It requires the server supports copy-file extension.
pub fn enable_copy(&mut self, enable_copy: bool) -> &mut Self {
self.enable_copy = enable_copy;

self
}
}

impl Builder for SftpBuilder {
Expand Down Expand Up @@ -225,6 +235,7 @@ impl Builder for SftpBuilder {
user,
key: self.key.clone(),
known_hosts_strategy,
copyable: self.enable_copy,
client: tokio::sync::OnceCell::new(),
})
}
Expand All @@ -250,6 +261,7 @@ pub struct SftpBackend {
user: String,
key: Option<String>,
known_hosts_strategy: KnownHosts,
copyable: bool,
client: tokio::sync::OnceCell<Sftp>,
}

Expand Down Expand Up @@ -278,6 +290,7 @@ impl Accessor for SftpBackend {

read: true,
read_with_range: true,
read_can_seek: true,

write: true,
write_without_content_length: true,
Expand All @@ -288,6 +301,7 @@ impl Accessor for SftpBackend {
list_with_limit: true,
list_with_delimiter_slash: true,

copy: self.copyable,
rename: true,

..Default::default()
Expand Down