January 2018
Beginner to intermediate
454 pages
10h 8m
English
A very useful feature of an FTP server is the ability to download files. So, it's time to add the command to do so.
First of all, we add the case in the handle_cmd() method:
#[async]
fn handle_cmd(mut self, cmd: Command) -> Result<Self> {
match cmd {
Command::Retr(file) => self = await!(self.retr(file))?,
// …
}
}
Here is the start of the retr() function:
use std::fs::File; use std::io::Read; use error::Error; #[async] fn retr(mut self, path: PathBuf) -> Result<Self> { if self.data_writer.is_some() { let path = self.cwd.join(path); let (new_self, res) = self.complete_path(path.clone()); self = new_self; if let Ok(path) = res { if path.is_file() { self = await!(self.send(Answer::new(ResultCode::DataConnectionAlreadyOpen, ...Read now
Unlock full access