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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use std::convert::From;
use std::error::Error;
use std::fmt;
pub type Result<T> = ::std::result::Result<T, FtpError>;
#[derive(Debug)]
pub enum FtpError {
ConnectionError(::std::io::Error),
SecureError(String),
InvalidResponse(String),
InvalidAddress(::std::net::AddrParseError),
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum FormatControl {
Default,
NonPrint,
Telnet,
Asa,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum FileType {
Ascii(FormatControl),
Ebcdic(FormatControl),
Image,
Binary,
Local(u8),
}
pub struct Line(pub u32, pub String);
impl ToString for FormatControl {
fn to_string(&self) -> String {
match self {
&FormatControl::Default | &FormatControl::NonPrint => String::from("N"),
&FormatControl::Telnet => String::from("T"),
&FormatControl::Asa => String::from("C"),
}
}
}
impl ToString for FileType {
fn to_string(&self) -> String {
match self {
&FileType::Ascii(ref fc) => format!("A {}", fc.to_string()),
&FileType::Ebcdic(ref fc) => format!("E {}", fc.to_string()),
&FileType::Image | &FileType::Binary => String::from("I"),
&FileType::Local(ref bits) => format!("L {}", bits),
}
}
}
impl fmt::Display for FtpError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
FtpError::ConnectionError(ref ioerr) => write!(f, "FTP ConnectionError: {}", ioerr),
FtpError::SecureError(ref desc) => write!(f, "FTP SecureError: {}", desc.clone()),
FtpError::InvalidResponse(ref desc) => {
write!(f, "FTP InvalidResponse: {}", desc.clone())
}
FtpError::InvalidAddress(ref perr) => write!(f, "FTP InvalidAddress: {}", perr),
}
}
}
impl Error for FtpError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
FtpError::ConnectionError(ref ioerr) => Some(ioerr),
FtpError::SecureError(_) => None,
FtpError::InvalidResponse(_) => None,
FtpError::InvalidAddress(ref perr) => Some(perr),
}
}
}