1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! The RFC 959 Change Working Directory (`CWD`) command
//
// This command allows the user to work with a different
// directory or dataset for file storage or retrieval without
// altering his login or accounting information. Transfer
// parameters are similarly unchanged. The argument is a
// pathname specifying a directory or other system dependent
// file group designator.
use crate::server::commands::Cmd;
use crate::server::error::FTPError;
use crate::server::reply::{Reply, ReplyCode};
use crate::server::CommandArgs;
use crate::storage;
use std::path::PathBuf;
pub struct Cwd {
path: PathBuf,
}
impl Cwd {
pub fn new(path: PathBuf) -> Self {
Cwd { path }
}
}
impl<S, U> Cmd<S, U> for Cwd
where
U: Send + Sync + 'static,
S: 'static + storage::StorageBackend<U> + Sync + Send,
S::File: tokio_io::AsyncRead + Send,
S::Metadata: storage::Metadata,
{
fn execute(&self, args: &CommandArgs<S, U>) -> Result<Reply, FTPError> {
// TODO: We current accept all CWD requests. Consider only allowing
// this if the directory actually exists and the user has the proper
// permission.
let mut session = args.session.lock()?;
session.cwd.push(self.path.clone());
Ok(Reply::new(ReplyCode::FileActionOkay, "OK"))
}
}