We still need to write an Encoder in order to have a codec that can send commands to FTP clients:
use ftp::Answer; impl Encoder for FtpCodec { type Item = Answer; type Error = io::Error; fn encode(&mut self, answer: Answer, buf: &mut BytesMut) -> io::Result<()> { let answer = if answer.message.is_empty() { format!("{}\r\n", answer.code as u32) } else { format!("{} {}\r\n", answer.code as u32,
answer.message) }; buf.extend(answer.as_bytes()); Ok(()) } }
Here, if we have a non-empty message, we push it to the buffer, preceded by the FTP code number. Otherwise, we only push this code number to the buffer.
We can now try the FTP server in FileZilla to see the following result:
