I am very new at RUST and am having difficulty with the SFTP connection.
I was trying to use openssh
with openssh_sftp_client
. This is the code I am working on (it is just from openssh
document).
use openssh::{Session, Stdio, SessionBuilder};
use openssh_sftp_client::Sftp;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let builder = SessionBuilder::default();
let (builder, destination) = builder.resolve("ssh://username@hostname:22");
let tempdir = builder.launch_master(destination).await?;
let session = Session::new_process_mux(tempdir);
println!("Session created");
let mut child = session
.subsystem("sftp")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.await?;
println!("Child spawned");
Sftp::new(
child.stdin().take().unwrap(),
child.stdout().take().unwrap(),
Default::default(),
)
.await?
.close()
.await?;
Ok(())
}
However, I cannot make it work. let session = Session::new_process_mux(tempdir);
part seems to be problematic. Below is the message I got when I ran the code.
Error: Connect(Custom { kind: ConnectionAborted,
error: "Unable to negotiate with 198.55.199.53 port 22: no matching key exchange method found.
Their offer: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1" })
When I accessed through Mac terminal, I used below config, and ~ $ sftp DATA
easily connects to the server.
Host DATA
HostName hostname
User username
KexAlgorithms +diffie-hellman-group14-sha1
HostKeyAlgorithms=+ssh-dss
I think KexAlgorithms and HostKeyAlgorithms parts are the problems I couldn’t incorporate into rust code. Is there any way to deal with this?