Skip to content

Manual connection setup #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/ftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct FtpStream {
}

impl FtpStream {
/// Creates an FTP Stream.
/// Creates a FTP Stream.
#[cfg(not(feature = "secure"))]
pub fn connect<A: ToSocketAddrs>(addr: A) -> Result<FtpStream> {
TcpStream::connect(addr)
Expand All @@ -52,7 +52,7 @@ impl FtpStream {
})
}

/// Creates an FTP Stream.
/// Creates a FTP Stream.
#[cfg(feature = "secure")]
pub fn connect<A: ToSocketAddrs>(addr: A) -> Result<FtpStream> {
TcpStream::connect(addr)
Expand All @@ -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<FtpStream> {
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.
Expand Down