Entering passive mode
Let's now write the code to handle the PASV command. Add the following case in handle_cmd():
#[async]
fn handle_cmd(mut self, cmd: Command) -> Result<Self> {
match cmd {
// …
Command::Pasv => self = await!(self.pasv())?,
// …
}
}For the following, we'll need four new fields in the Client structure:
use futures::stream::SplitStream;
use codec::BytesCodec;
type DataReader = SplitStream<Framed<TcpStream, BytesCodec>>;
type DataWriter = SplitSink<Framed<TcpStream, BytesCodec>>;
struct Client {
data_port: Option<u16>,
data_reader: Option<DataReader>,
data_writer: Option<DataWriter>,
handle: Handle,
// …
}And all of them are initialized to None:
impl Client {
fn new(handle: Handle, writer: Writer, server_root: PathBuf) -> Client {
Client {
data_port: None,
data_reader: None,
data_writer: None,
handle,
...