From a6a14c73581fbf07cbcd70b483859ae0487e8997 Mon Sep 17 00:00:00 2001 From: Urs Schulz Date: Wed, 2 Jan 2019 10:52:59 +0100 Subject: [PATCH 1/2] fix doc typos --- src/ftp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ftp.rs b/src/ftp.rs index 6f87e3347..38febb729 100644 --- a/src/ftp.rs +++ b/src/ftp.rs @@ -38,7 +38,7 @@ pub struct FtpStream { } impl FtpStream { - /// Creates an FTP Stream. + /// Creates a FTP Stream. #[cfg(not(feature = "secure"))] pub fn connect(addr: A) -> Result { TcpStream::connect(addr) @@ -52,7 +52,7 @@ impl FtpStream { }) } - /// Creates an FTP Stream. + /// Creates a FTP Stream. #[cfg(feature = "secure")] pub fn connect(addr: A) -> Result { TcpStream::connect(addr) From b0ce44f9459c04555e51921c4d66c0dd8375eda5 Mon Sep 17 00:00:00 2001 From: Urs Schulz Date: Wed, 2 Jan 2019 10:58:00 +0100 Subject: [PATCH 2/2] implement manual connection setup --- src/ftp.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ftp.rs b/src/ftp.rs index 38febb729..040f222b0 100644 --- a/src/ftp.rs +++ b/src/ftp.rs @@ -66,6 +66,19 @@ impl FtpStream { .map(|_| ftp_stream) }) } + + /// Creates a FTP Stream from an existing TcpStream. + /// This method is useful, if you want to do the connection setup on your own. + pub fn from_tcp(stream: TcpStream) -> Result { + let mut ftp_stream = FtpStream { + reader: BufReader::new(DataStream::Tcp(stream)), + #[cfg(feature = "secure")] + ssl_cfg: None, + }; + + ftp_stream.read_response(status::READY) + .map(|_| ftp_stream) + } /// Switch to a secure mode if possible, using a provided SSL configuration. /// This method does nothing if the connect is already secured.