Skip to content

Commit 3d93a70

Browse files
zsckmattnenterprise
authored andcommitted
Unify the library's interface and tidy up some code (#47)
Unify the library's interface and tidy up some code
1 parent 2e51b31 commit 3d93a70

File tree

5 files changed

+236
-260
lines changed

5 files changed

+236
-260
lines changed

examples/connecting.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
extern crate ftp;
22

33
use std::str;
4-
use std::io::{Cursor, Error, ErrorKind, Result};
5-
use ftp::FtpStream;
4+
use std::io::Cursor;
5+
use ftp::{FtpStream, FtpError};
66

7-
fn test_ftp(addr: &str, user: &str, pass: &str) -> Result<()> {
8-
let mut ftp_stream = try!(FtpStream::connect((addr, 21)));
9-
try!(ftp_stream.login(user, pass));
10-
println!("current dir: {}", try!(ftp_stream.pwd()));
7+
fn test_ftp(addr: &str, user: &str, pass: &str) -> Result<(), FtpError> {
8+
let mut ftp_stream = FtpStream::connect((addr, 21)).unwrap();
9+
ftp_stream.login(user, pass).unwrap();
10+
println!("current dir: {}", ftp_stream.pwd().unwrap());
1111

12-
try!(ftp_stream.cwd("test_data"));
12+
ftp_stream.cwd("test_data").unwrap();
1313

1414
// An easy way to retrieve a file
15-
let cursor = try!(ftp_stream.simple_retr("ftpext-charter.txt"));
15+
let cursor = ftp_stream.simple_retr("ftpext-charter.txt").unwrap();
1616
let vec = cursor.into_inner();
17-
let text = try!(str::from_utf8(&vec).or_else(|cause|
18-
Err(Error::new(ErrorKind::Other, cause))
19-
));
17+
let text = str::from_utf8(&vec).unwrap();
2018
println!("got data: {}", text);
2119

2220
// Store a file
2321
let file_data = format!("Some awesome file data man!!");
2422
let mut reader = Cursor::new(file_data.into_bytes());
25-
try!(ftp_stream.put("my_random_file.txt", &mut reader));
23+
ftp_stream.put("my_random_file.txt", &mut reader).unwrap();
2624

2725
ftp_stream.quit()
2826
}
2927

3028
fn main() {
31-
test_ftp("127.0.0.1", "Doe", "mumble").unwrap_or_else(|err|
32-
panic!("{}", err)
33-
);
29+
test_ftp("127.0.0.1", "anonymous", "[email protected]").unwrap();
3430
println!("test successful")
3531
}

0 commit comments

Comments
 (0)