Managing the current working directory
There are still a few commands missing before we can see the files in the FTP client. Let's now add the command to print the current directory and to change it.
Printing the current directory
First of all, we'll need a new attribute for our Client structure to specify what the current directory is:
use std::path::PathBuf;
struct Client {
cwd: PathBuf,
writer: Writer,
}The cwd attribute stands for current working directory. We also need to update the Client constructor accordingly:
impl Client {
fn new(writer: Writer) -> Client {
Client {
cwd: PathBuf::from("/"),
writer,
}
}
}Now, we can add the handler for the PWD command:
#[async]
fn handle_cmd(mut self, cmd: Command) -> Result<Self> {
println!("Received command: {:?}", cmd);
match cmd {
Command::Pwd => {
let msg = format!("{}", self.cwd.to_str().unwrap_or(""));
if !msg.is_empty() {
...