ftp_cmd_list_parse/lib.rs
1//! # ftp-cmd-list-parse
2//!
3//! This is a library that can parse strings that FTP servers return
4//! by `LIST` command request.
5//!
6//! * Unix-style:
7//! ```text
8//! drwxr-xr-x 10 root root 4096 Dec 21 2012 usr
9//! brw-rw---- 1 root disk 8, 0 Nov 24 10:13 sda
10//! -rw-rw-rw- 1 owner 1234 7045120 Sep 02 2012 music.mp3
11//! lrwxrwxrwx 1 root root 51 Apr 4 23:57 www.nodeftp.github -> /etc/nginx/sites-available/www.nodeftp.github
12//! ```
13//!
14//! * Msdos-style:
15//! ```text
16//! 08-22-2018 02:05PM <DIR> wwwroot
17//! 08-22-18 12:59PM 99710 logo.jpg
18//! 08-22-18 03:01AM 99710 music.mp3
19//! ```
20//!
21//! ## Examples:
22//!
23//! ```rust
24//! use ftp_cmd_list_parse::FtpEntry;
25//!
26//! let ftp_response: &'static str = "drwxr-xr-x 10 root root 4096 Dec 21 2012 usr";
27//! if let Some(ftp_entry) = FtpEntry::new(ftp_response) {
28//! println!("{}", ftp_entry.name()); // "usr"
29//! println!("{:?}", ftp_entry.kind()); // FtpEntryKind::Directory
30//!
31//! assert!(ftp_entry.is_unix_type()); // true
32//! }
33//! ```
34//!
35//! You need convert `FtpEntry` to `FtpEntryUnix` to see additional
36//! fields that MSDOS FTP server doesn't support:
37//!
38//! ```rust
39//! use std::convert::TryFrom;
40//! use ftp_cmd_list_parse::FtpEntry;
41//!
42//! let ftp_response: &'static str = "drwxr-xr-x 10 root root 4096 Dec 21 2012 usr";
43//!
44//! if let Ok(ftp_entry) = FtpEntry::try_from(ftp_response) {
45//! match ftp_entry.try_to_unix_type() {
46//! Ok(ftp_entry_unix) => { // `FtpEntryUnix` type
47//! println!("Owner: {}", ftp_entry_unix.owner); // "root"
48//! println!("Group: {}", ftp_entry_unix.group); // "root"
49//! println!("Permissions: {}", ftp_entry_unix.permissions.as_str()); // "rwxr-xr-x"
50//! },
51//! Err(ftp_entry) => { // `FtpEntry` type
52//! // Here we got our `FtpEntry` back.
53//! println!("FtpEntry is not an UNIX-format!");
54//! }
55//! }
56//!
57//! // Also you can use pattern-matching to destruct enum:
58//! // if let FtpEntry::Msdos(ftp_entry_msdos) = ftp_entry {
59//! // println!("name: {}", ftp_entry_msdos.name()); // prints "name: usr"
60//! //}
61//! }
62//! ```
63//!
64//! If you ensure what type of FTP server using, you can create `FtpEntryUnix`
65//! or `FtpEntryMsdos` struct directly:
66//!
67//! ```rust
68//! use ftp_cmd_list_parse::FtpEntryUnix;
69//!
70//! let ftp_response: &'static str = "drwxr-xr-x 10 root root 4096 Dec 21 2012 usr";
71//! if let Some(ftp_entry_unix) = FtpEntryUnix::new(ftp_response) {
72//! println!("Owner: {}", ftp_entry_unix.owner); // "root"
73//! println!("Group: {}", ftp_entry_unix.group); // "root"
74//! println!("Permissions: {}", ftp_entry_unix.permissions); // "rwxr-xr-x"
75//! }
76//! ```
77
78#[macro_use]
79extern crate lazy_static;
80
81mod entry;
82pub use entry::*;