pub use self::port::PORT;
pub use self::mode::{MODE, Mode};
pub use self::basic::{ABOR, CDUP, EPSV, FEAT, NOOP, PASV, PWD,
QUIT, REIN, STOU, SYST};
pub use self::misc::{ACCT, APPE, CWD, DELE, HELP, LIST, MDTM, MKD, NLST,
RETR, RMD, RNFR, RNTO, SITE, SIZE, STAT, STOR, TYPE,
USER, PASS};
pub use self::security::{ADAT, AUTH, CCC, CONF, ENC, MIC, PBSZ, PROT};
pub use self::unimplemented::*;
#[macro_use]
pub mod macros;
pub mod port;
pub mod mode;
pub mod basic;
pub mod misc;
pub mod security;
pub mod unimplemented;
use Error;
use std::io::prelude::*;
use std::{io, fmt};
pub trait Command : Clone + fmt::Debug + PartialEq + Eq
{
fn write(&self, write: &mut Write) -> Result<(), Error> {
let mut payload_buffer = io::Cursor::new(Vec::new());
self.write_payload(&mut payload_buffer)?;
let payload = payload_buffer.into_inner();
if payload.is_empty() {
write!(write, "{}", self.command_name())?;
} else {
write!(write, "{} ", self.command_name())?;
write.write(&payload)?;
}
Ok(())
}
fn write_payload(&self, write: &mut Write) -> Result<(), Error>;
fn read_payload(read: &mut BufRead) -> Result<Self, Error>;
fn command_name(&self) -> &'static str;
fn bytes(&self) -> Vec<u8> {
let mut buffer = io::Cursor::new(Vec::new());
self.write(&mut buffer).expect("IO failure while writing to memory buffer");
buffer.into_inner()
}
fn to_string(&self) -> String {
String::from_utf8(self.bytes()).unwrap()
}
}