January 2018
Beginner to intermediate
454 pages
10h 8m
English
Now that we can handle a data connection, let's implement the LIST! For now, let's implement it without parameters (once again, we'll see in later chapters how to handle the LIST parameter). As usual, I'll let you add everything where it's needed and we'll just focus on the command handling:
Command::List => { if let Some(ref mut data_writer) = self.data_writer { let mut tmp = PathBuf::from("."); send_cmd(&mut self.stream, ResultCode::DataConnectionAlreadyOpen, "Starting to list directory..."); let mut out = String::new(); for entry in read_dir(tmp).unwrap() { for entry in dir { if let Ok(entry) = entry { add_file_info(entry.path(), &mut out); } } send_data(data_writer, &out) } } else { send_cmd(&mut self.stream, ...