January 2018
Beginner to intermediate
454 pages
10h 8m
English
To be able to make this command work, we need to add a few new fields in our Client struct:
struct Client {
cwd: PathBuf,
stream: TcpStream,
name: Option<String>,
data_writer: Option<TcpStream>,
}
We now need to update the Client::new method as well:
fn new(stream: TcpStream) -> Client {
Client {
cwd: PathBuf::from("/"),
stream: stream,
name: None,
data_writer: None,
}
}
The PASV command doesn't take arguments, so I'll let you add it to the structures and everything. Let's focus on the interesting part:
// Adding some new imports:
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
Command::Pasv => {
if self.data_writer.is_some() {
send_cmd(&mut self.stream, ResultCode::DataConnectionAlreadyOpen, "Already listening...") ...Read now
Unlock full access