|
1 | 1 | extern crate ftp;
|
2 | 2 |
|
3 | 3 | 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}; |
6 | 6 |
|
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()); |
11 | 11 |
|
12 |
| - try!(ftp_stream.cwd("test_data")); |
| 12 | + ftp_stream.cwd("test_data").unwrap(); |
13 | 13 |
|
14 | 14 | // 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(); |
16 | 16 | 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(); |
20 | 18 | println!("got data: {}", text);
|
21 | 19 |
|
22 | 20 | // Store a file
|
23 | 21 | let file_data = format!("Some awesome file data man!!");
|
24 | 22 | 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(); |
26 | 24 |
|
27 | 25 | ftp_stream.quit()
|
28 | 26 | }
|
29 | 27 |
|
30 | 28 | 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(); |
34 | 30 | println!("test successful")
|
35 | 31 | }
|
0 commit comments