We'll start this chapter by implementing the command to list files. This will allow us to actually see the files in an FTP client, and we'll be able to tests some commands from the previous chapter by navigating in the directories. So, let's add a case in the Client::handle_cmd() method:
#[async] fn handle_cmd(mut self, cmd: Command) -> Result<Self> { match cmd { Command::List(path) => self = await!(self.list(path))?, // … } }
This simply calls the list() method, which begins as follows:
use std::fs::read_dir; #[async] fn list(mut self, path: Option<PathBuf>) -> Result<Self> { if self.data_writer.is_some() { let path = self.cwd.join(path.unwrap_or_default()); let directory = PathBuf::from(&path); let (new_self, res) = self.complete_path(directory); ...