feat: continuing work on downloading files

This commit is contained in:
Andrew Rioux
2023-09-06 19:44:13 -04:00
parent 50b5c1a921
commit cd23ec1b80
5 changed files with 146 additions and 15 deletions

View File

@@ -16,13 +16,13 @@ pub async fn download_file(
remote_file: PathBuf,
local_path: PathBuf,
) -> anyhow::Result<()> {
let mut file = fs::OpenOptions::new().read(true).open(&local_path).await?;
let file_size = file.metadata().await?.len();
let mut file = fs::OpenOptions::new()
.write(true)
.create(true)
.open(&local_path)
.await?;
let command = Command::StartUploadFile(
remote_path,
(file_size / FILE_TRANSFER_PACKET_SIZE as u64) + 1,
);
let command = Command::StartDownloadFile(remote_file);
conn.send_command(command).await?;
let id = loop {

View File

@@ -215,9 +215,12 @@ pub(super) async fn shell(
}),
_,
) => {
if let Err(e) =
commands::download::download(Arc::clone(&connection), remote_file, local_path)
.await
if let Err(e) = commands::download::download_file(
Arc::clone(&connection),
remote_file,
local_path,
)
.await
{
eprintln!("{e:?}")
}