Skip to content

Commit

Permalink
Use SFTP instead of SCP to copy file
Browse files Browse the repository at this point in the history
Fix SCP not working on well with Windows guests. Switch over to
SFTP instead
  • Loading branch information
MarkusPettersson98 committed Dec 13, 2024
1 parent 8de6bf8 commit a3a6156
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions test/test-manager/src/vm/provision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,11 @@ fn ssh_send_file<P: AsRef<Path> + Copy>(
}

/// Analogues to [`std::fs::write`], but over ssh!
fn ssh_write<P: AsRef<Path>, C: AsRef<[u8]>>(session: &Session, dest: P, source: C) -> Result<()> {
let bytes = source.as_ref();
fn ssh_write<P: AsRef<Path>>(session: &Session, dest: P, mut source: impl Read) -> Result<()> {
let sftp = session.sftp()?;
let mut remote_file = sftp.create(dest.as_ref())?;

let source = &mut &bytes[..];
let source_len = u64::try_from(bytes.len()).context("File too large, did not fit in a u64")?;

let mut remote_file = session.scp_send(dest.as_ref(), 0o744, source_len, None)?;

io::copy(source, &mut remote_file).context("failed to write file")?;

remote_file.send_eof()?;
remote_file.wait_eof()?;
remote_file.close()?;
remote_file.wait_close()?;
io::copy(&mut source, &mut remote_file).context("failed to write file")?;

Ok(())
}
Expand Down

0 comments on commit a3a6156

Please sign in to comment.