SFTP
SFTP services support. (only works on unix)
caution
Maximum number of file holdings is depending on the remote system configuration.
For example, the default value is 255 in macOS, and 1024 in linux. If you want to open lots of files, you should pay attention to close the file after using it.
Capabilities
This service can be used to:
- stat
- read
- write
- append
- create_dir
- delete
- copy
- rename
- list
-
presign - blocking
Configuration
endpoint
: Set the endpoint for connection. The format is same asopenssh
, using either[user@]hostname
orssh://[user@]hostname[:port]
. A username or port that is specified in the endpoint overrides the one set in the builder (but does not change the builder).root
: Set the work directory for backend. It uses the default directory set by the remotesftp-server
as defaultuser
: Set the login userkey
: Set the public key for loginknown_hosts_strategy
: Set the strategy for known hosts, default toStrict
enable_copy
: Set whether the remote server has copy-file extension
For security reasons, it doesn't support password login, you can use public key or ssh-copy-id instead.
You can refer to [SftpBuilder
]'s docs for more information
Example
Via Builder
use anyhow::Result;
use opendal::services::Sftp;
use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
let mut builder = Sftp::default();
builder.endpoint("127.0.0.1").user("test").key("test_key");
let op: Operator = Operator::new(builder)?.finish();
Ok(())
}
Via Config
- Rust
- Node.js
- Python
use anyhow::Result;
use opendal::Operator;
use opendal::Scheme;
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
map.insert("endpoint".to_string(), "127.0.0.1".to_string());
map.insert("user".to_string(), "test".to_string());
map.insert("key".to_string(), "test_key".to_string());
let op: Operator = Operator::via_map(Scheme::Sftp, map)?;
Ok(())
}
import { Operator } from "opendal";
async function main() {
const op = new Operator("sftp", {
endpoint: "127.0.0.1",
user: "test",
key: "test_key",
});
}
import opendal
op = opendal.Operator("sftp",
endpoint="127.0.0.1",
user="test",
key="test_key",
)