LoU
1
Hi,
I'm fairly new around rust. So please be patient with me
I tried to upload file (image/zip) to FTP, it's ok with example provided by GitHub - mattnenterprise/rust-ftp: FTP client for Rust (ftp 2.0.0 cargo) and i stuck.
What should I do? I've tried with opening file and read as VEC and String (based on What's the de-facto way of reading and writing files in Rust 1.x? - Stack Overflow) And failed.
What is the proper way to upload specified file by path to ftp? Couldn't find a solution around.
Thanks for tips and help
edit:
> let mut file = File::open("/home/emjot/Pictures/test2.png").unwrap();
// what should be here?
let _ = ftp_stream.put("greeting.png", &mut _AND_HERE_);
1 Like
Hi LoU and welcome to Rust!
So
ftp_stream.put()
expects anything that implements the Read trait:
And File
implements the Read
trait:
So this should work (untested):
let mut file = File::open("/home/emjot/Pictures/test2.png").unwrap();
ftp_stream.transfer_type(FileType::Image)
let _ = ftp_stream.put("greeting.png", &mut file);
I've added the transfer type to ensure that binary transfer is used instead of text mode.
Hope this helps!
1 Like
LoU
3
Hi Will,
Thanks for reply. I've tried using transfer_type before and couldn't figure out how to do this properly.
Every time it threw error while compiling:
with: use use std::fs::FileType;
no associated item named Image
found for type std::fs::FileType
in the current scope
without:use use std::fs::FileType;
failed to resolve. Use of undeclared type or module FileType
[E0433]
Also tried Binary instead of Image, yet same error occurs.
Ah sorry, the enum FileType
is from the ftp
crate and thus must be imported like this:
use ftp::types::FileType;
1 Like
LoU
5
Thanks @willi_kappler it worked.
Once again thanks for help and warm welcome, and patience
Tested with binary with :
use ftp::types::FileType;
let mut file = File::open("/home/emjot/Pictures/test2.png").unwrap();
ftp_stream.transfer_type(FileType::Binary);
let _ = ftp_stream.put("greeting.png", &mut file);