|
9 | 9 | //!
|
10 | 10 | //! ```rust
|
11 | 11 | //! use ftp::FtpStream;
|
12 |
| -//! let mut (ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap_or_else(|err| |
| 12 | +//! let (mut ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap_or_else(|err| |
13 | 13 | //! panic!("{}", err)
|
14 | 14 | //! );
|
15 | 15 | //! let _ = ftp_stream.quit();
|
|
28 | 28 | //! For better security it's the good practice to switch to the secure mode
|
29 | 29 | //! before authentication.
|
30 | 30 | //!
|
31 |
| -//! ## FTPS Usage |
32 |
| -//! |
33 |
| -//! ```rust,no_run |
34 |
| -//! use ftp::FtpStream; |
35 |
| -//! use ftp::openssl::ssl::{ SslContext, SslMethod }; |
36 |
| -//! |
37 |
| -//! let (ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap(); |
38 |
| -//! let ctx = SslContext::builder(SslMethod::tls()).unwrap().build(); |
39 |
| -//! // Switch to the secure mode |
40 |
| -//! let mut ftp_stream = ftp_stream.into_secure(ctx).unwrap(); |
41 |
| -//! ftp_stream.login("anonymous", "anonymous").unwrap(); |
42 |
| -//! // Do other secret stuff |
43 |
| -//! // Switch back to the insecure mode (if required) |
44 |
| -//! let mut ftp_stream = ftp_stream.into_insecure().unwrap(); |
45 |
| -//! // Do all public stuff |
46 |
| -//! let _ = ftp_stream.quit(); |
47 |
| -//! ``` |
48 |
| -//! |
49 |
| -//! ## FTPS Usage with native-tls |
50 |
| -//! |
51 |
| -//! ```rust,no_run |
52 |
| -//! use ftp::FtpStream; |
53 |
| -//! use ftp::native_tls::{TlsConnector, TlsStream}; |
54 |
| -//! |
55 |
| -//! let (ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap(); |
56 |
| -//! let mut ctx = TlsConnector::new().unwrap(); |
57 |
| -//! // Switch to the secure mode |
58 |
| -//! let mut ftp_stream = ftp_stream.into_secure(ctx, "localhost").unwrap(); |
59 |
| -//! ftp_stream.login("anonymous", "anonymous").unwrap(); |
60 |
| -//! // Do other secret stuff |
61 |
| -//! // Switch back to the insecure mode (if required) |
62 |
| -//! let mut ftp_stream = ftp_stream.into_insecure().unwrap(); |
63 |
| -//! // Do all public stuff |
64 |
| -//! let _ = ftp_stream.quit(); |
65 |
| -//! ``` |
66 |
| -//! |
| 31 | +#![cfg_attr( |
| 32 | + all(feature = "secure", not(feature = "native-tls")), |
| 33 | + doc = r##" |
| 34 | +## FTPS Usage |
| 35 | +
|
| 36 | +```rust,no_run |
| 37 | +use ftp::FtpStream; |
| 38 | +use ftp::openssl::ssl::{ SslContext, SslMethod }; |
| 39 | +
|
| 40 | +let (ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap(); |
| 41 | +let ctx = SslContext::builder(SslMethod::tls()).unwrap().build(); |
| 42 | +// Switch to the secure mode |
| 43 | +let mut ftp_stream = ftp_stream.into_secure(ctx).unwrap(); |
| 44 | +ftp_stream.login("anonymous", "anonymous").unwrap(); |
| 45 | +// Do other secret stuff |
| 46 | +// Switch back to the insecure mode (if required) |
| 47 | +let mut ftp_stream = ftp_stream.into_insecure().unwrap(); |
| 48 | +// Do all public stuff |
| 49 | +let _ = ftp_stream.quit(); |
| 50 | +``` |
| 51 | +"## |
| 52 | +)] |
| 53 | +#![cfg_attr( |
| 54 | + all(feature = "secure", feature = "native-tls"), |
| 55 | + doc = r##" |
| 56 | +## FTPS Usage |
| 57 | +
|
| 58 | +```rust,no_run |
| 59 | +use ftp::FtpStream; |
| 60 | +use ftp::native_tls::{TlsConnector, TlsStream}; |
67 | 61 |
|
| 62 | +let (ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap(); |
| 63 | +let mut ctx = TlsConnector::new().unwrap(); |
| 64 | +// Switch to the secure mode |
| 65 | +let mut ftp_stream = ftp_stream.into_secure(ctx, "localhost").unwrap(); |
| 66 | +ftp_stream.login("anonymous", "anonymous").unwrap(); |
| 67 | +// Do other secret stuff |
| 68 | +// Switch back to the insecure mode (if required) |
| 69 | +let mut ftp_stream = ftp_stream.into_insecure().unwrap(); |
| 70 | +// Do all public stuff |
| 71 | +let _ = ftp_stream.quit(); |
| 72 | +``` |
| 73 | +"## |
| 74 | +)] |
68 | 75 | #[macro_use]
|
69 | 76 | extern crate lazy_static;
|
70 | 77 | extern crate chrono;
|
|
0 commit comments