I am currently working on a program to recursively step through the directories of an FTP server, which then clones the chosen directory to the local computer.
The program runs fine and identifies all files and folders with the correct structure etc. However my issue is that when some files are transferred, they are corrupted e.g. jpeg files with only the top third of the image intact and the rest all jumbled garbage (it looks to me like an incomplete transfer or an issue with writing of the contents to disk). I have copied the files from the server using Filezilla and they are fully intact with no corruption.
I am using the "ftp-client" crate from crates.io and it seems to do everything I need. Below is the portion of the code which retrieves the file and writes it to my local PC. I am wondering if I either need to confirm that the file is fully received from the ftp server before writing to the disk or do I need to somehow give the program enough time to write the contents locally to disk before moving on to the next file? Are there any buffers at play here in the background that need to be flushed out before the program moves to the next file?
Appreciate if anyone has any tips on file transfers or on what may be causing the corruption.
//retrieve the file from the current working directory let remote_file_path = String::from("./") + &components; //e.g. "./file.text" let remote_file = client.retrieve_file(&remote_file_path).unwrap(); //write the file to disk let mut local_file = File::create(&local_file_path).unwrap(); local_file.write_all(&remote_file).unwrap();