From 5b22da525492938aa5616af4b6491e7ac1f3c7e6 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Fri, 10 Nov 2023 11:46:02 +1100 Subject: [PATCH] Use cat instead of dd for transferring files (#32) --- .../examples/aws-throwaway-test-large-file.rs | 12 ++++++++++++ aws-throwaway/src/ssh.rs | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/aws-throwaway/examples/aws-throwaway-test-large-file.rs b/aws-throwaway/examples/aws-throwaway-test-large-file.rs index d923161..0168299 100644 --- a/aws-throwaway/examples/aws-throwaway-test-large-file.rs +++ b/aws-throwaway/examples/aws-throwaway-test-large-file.rs @@ -28,6 +28,18 @@ async fn main() { .await; println!("Time to push 100MB file {:?}", start.elapsed()); + let remote_size: usize = instance + .ssh() + .shell("wc -c some_remote_file") + .await + .stdout + .split_ascii_whitespace() + .next() + .unwrap() + .parse() + .unwrap(); + assert_eq!(remote_size, FILE_LEN); + let start = Instant::now(); instance .ssh() diff --git a/aws-throwaway/src/ssh.rs b/aws-throwaway/src/ssh.rs index a6e3a1c..2f76819 100644 --- a/aws-throwaway/src/ssh.rs +++ b/aws-throwaway/src/ssh.rs @@ -210,7 +210,7 @@ impl SshConnection { async fn push_file_impl(&self, task: &str, source: R, dest: &Path) { let mut channel = self.session.channel_open_session().await.unwrap(); - let command = format!("dd of='{0}'\nchmod 777 {0}", dest.to_str().unwrap()); + let command = format!("cat > '{0}'\nchmod 777 {0}", dest.to_str().unwrap()); channel.exec(true, command).await.unwrap(); let mut stdout = vec![]; @@ -260,7 +260,7 @@ impl SshConnection { tracing::info!("{task}"); let mut channel = self.session.channel_open_session().await.unwrap(); - let command = format!("dd if='{0}'\nchmod 777 {0}", source.to_str().unwrap()); + let command = format!("cat '{}'", source.to_str().unwrap()); channel.exec(true, command).await.unwrap(); let mut out = File::create(dest).await.unwrap();