[SOLVED] FTP Upload any file



I’m fairly new around rust. So please be patient with me :slight_smile:

I tried to upload file (image/zip) to FTP, it’s ok with example provided by https://github.com/mattnenterprise/rust-ftp (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 http://stackoverflow.com/questions/31192956/whats-the-de-facto-way-of-reading-and-writing-files-now) 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 :slight_smile:

> let mut file = File::open("/home/emjot/Pictures/test2.png").unwrap();

// what should be here?
let _ = ftp_stream.put("greeting.png", &mut _AND_HERE_);


Hi LoU and welcome to Rust!



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();
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!


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;


Thanks @willi_kappler it worked.

Once again thanks for help and warm welcome, and patience :slight_smile:

Tested with binary with :

use ftp::types::FileType;

let mut file = File::open("/home/emjot/Pictures/test2.png").unwrap();
    let _ = ftp_stream.put("greeting.png", &mut file);