pub struct FtpStream { /* private fields */ }
Expand description
Stream to interface with the FTP server. This interface is only for the command stream.
Implementations
sourceimpl FtpStream
impl FtpStream
sourcepub fn connect<A: ToSocketAddrs>(addr: A) -> FtpResult<Self>
pub fn connect<A: ToSocketAddrs>(addr: A) -> FtpResult<Self>
Creates an FTP Stream.
sourcepub fn active_mode(self) -> Self
pub fn active_mode(self) -> Self
Enable active mode for data channel
sourcepub fn set_passive_nat_workaround(&mut self, nat_workaround: bool)
pub fn set_passive_nat_workaround(&mut self, nat_workaround: bool)
Set NAT workaround for passive mode
sourcepub fn get_welcome_msg(&self) -> Option<&str>
pub fn get_welcome_msg(&self) -> Option<&str>
Returns welcome message retrieved from server (if available)
sourcepub fn get_ref(&self) -> &TcpStream
pub fn get_ref(&self) -> &TcpStream
Returns a reference to the underlying TcpStream.
Example:
use suppaftp::FtpStream;
use std::net::TcpStream;
use std::time::Duration;
let stream = FtpStream::connect("127.0.0.1:21")
.expect("Couldn't connect to the server...");
stream.get_ref().set_read_timeout(Some(Duration::from_secs(10)))
.expect("set_read_timeout call failed");
Runsourcepub fn login<S: AsRef<str>>(&mut self, user: S, password: S) -> FtpResult<()>
pub fn login<S: AsRef<str>>(&mut self, user: S, password: S) -> FtpResult<()>
Log in to the FTP server.
sourcepub fn cwd<S: AsRef<str>>(&mut self, path: S) -> FtpResult<()>
pub fn cwd<S: AsRef<str>>(&mut self, path: S) -> FtpResult<()>
Change the current directory to the path specified.
sourcepub fn noop(&mut self) -> FtpResult<()>
pub fn noop(&mut self) -> FtpResult<()>
This does nothing. This is usually just used to keep the connection open.
sourcepub fn mkdir<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<()>
pub fn mkdir<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<()>
This creates a new directory on the server.
sourcepub fn transfer_type(&mut self, file_type: FileType) -> FtpResult<()>
pub fn transfer_type(&mut self, file_type: FileType) -> FtpResult<()>
Sets the type of file to be transferred. That is the implementation
of TYPE
command.
sourcepub fn rename<S: AsRef<str>>(&mut self, from_name: S, to_name: S) -> FtpResult<()>
pub fn rename<S: AsRef<str>>(&mut self, from_name: S, to_name: S) -> FtpResult<()>
Renames the file from_name to to_name
sourcepub fn retr<F, T>(&mut self, file_name: &str, reader: F) -> FtpResult<T> where
F: FnMut(&mut dyn Read) -> FtpResult<T>,
pub fn retr<F, T>(&mut self, file_name: &str, reader: F) -> FtpResult<T> where
F: FnMut(&mut dyn Read) -> FtpResult<T>,
The implementation of RETR
command where filename
is the name of the file
to download from FTP and reader
is the function which operates with the
data stream opened.
assert!(conn.retr("retr.txt", |stream| {
let mut buf = Vec::new();
stream.read_to_end(&mut buf).map(|_|
assert_eq!(buf, "hello, world!".as_bytes())
).map_err(|e| FtpError::ConnectionError(e))
}).is_ok());
Runsourcepub fn retr_as_buffer(&mut self, file_name: &str) -> FtpResult<Cursor<Vec<u8>>>
pub fn retr_as_buffer(&mut self, file_name: &str) -> FtpResult<Cursor<Vec<u8>>>
Simple way to retr a file from the server. This stores the file in a buffer in memory.
let cursor = conn.retr_as_buffer("simple_retr.txt").unwrap();
// do something with bytes
assert_eq!(cursor.into_inner(), "hello, world!".as_bytes());
Runsourcepub fn retr_as_stream<S: AsRef<str>>(
&mut self,
file_name: S
) -> FtpResult<DataStream>
pub fn retr_as_stream<S: AsRef<str>>(
&mut self,
file_name: S
) -> FtpResult<DataStream>
Retrieves the file name specified from the server as a readable stream.
This method is a more complicated way to retrieve a file.
The reader returned should be dropped.
Also you will have to read the response to make sure it has the correct value.
Once file has been read, call finalize_retr_stream()
sourcepub fn finalize_retr_stream(&mut self, stream: impl Read) -> FtpResult<()>
pub fn finalize_retr_stream(&mut self, stream: impl Read) -> FtpResult<()>
Finalize retr stream; must be called once the requested file, got previously with retr_as_stream()
has been read
sourcepub fn rmdir<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<()>
pub fn rmdir<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<()>
Removes the remote pathname from the server.
sourcepub fn rm<S: AsRef<str>>(&mut self, filename: S) -> FtpResult<()>
pub fn rm<S: AsRef<str>>(&mut self, filename: S) -> FtpResult<()>
Remove the remote file from the server.
sourcepub fn put_file<S: AsRef<str>, R: Read>(
&mut self,
filename: S,
r: &mut R
) -> FtpResult<u64>
pub fn put_file<S: AsRef<str>, R: Read>(
&mut self,
filename: S,
r: &mut R
) -> FtpResult<u64>
This stores a file on the server. r argument must be any struct which implemenents the Read trait. Returns amount of written bytes
sourcepub fn put_with_stream<S: AsRef<str>>(
&mut self,
filename: S
) -> FtpResult<DataStream>
pub fn put_with_stream<S: AsRef<str>>(
&mut self,
filename: S
) -> FtpResult<DataStream>
Send PUT command and returns a BufWriter, which references the file created on the server
The returned stream must be then correctly manipulated to write the content of the source file to the remote destination
The stream must be then correctly dropped.
Once you’ve finished the write, YOU MUST CALL THIS METHOD: finalize_put_stream
sourcepub fn finalize_put_stream(&mut self, stream: impl Write) -> FtpResult<()>
pub fn finalize_put_stream(&mut self, stream: impl Write) -> FtpResult<()>
Finalize put when using stream
This method must be called once the file has been written and
put_with_stream
has been used to write the file
sourcepub fn append_with_stream<S: AsRef<str>>(
&mut self,
filename: S
) -> FtpResult<DataStream>
pub fn append_with_stream<S: AsRef<str>>(
&mut self,
filename: S
) -> FtpResult<DataStream>
Open specified file for appending data. Returns the stream to append data to specified file.
Once you’ve finished the write, YOU MUST CALL THIS METHOD: finalize_put_stream
sourcepub fn append_file<R: Read>(
&mut self,
filename: &str,
r: &mut R
) -> FtpResult<u64>
pub fn append_file<R: Read>(
&mut self,
filename: &str,
r: &mut R
) -> FtpResult<u64>
Append data from reader to file at filename
sourcepub fn abort(&mut self, data_stream: impl Read) -> FtpResult<()>
pub fn abort(&mut self, data_stream: impl Read) -> FtpResult<()>
abort the previous FTP service command
sourcepub fn resume_transfer(&mut self, offset: usize) -> FtpResult<()>
pub fn resume_transfer(&mut self, offset: usize) -> FtpResult<()>
Tell the server to resume the transfer from a certain offset. The offset indicates the amount of bytes to skip from the beginning of the file. the REST command does not actually initiate the transfer. After issuing a REST command, the client must send the appropriate FTP command to transfer the file
It is possible to cancel the REST command, sending a REST command with offset 0
sourcepub fn list(&mut self, pathname: Option<&str>) -> FtpResult<Vec<String>>
pub fn list(&mut self, pathname: Option<&str>) -> FtpResult<Vec<String>>
Execute LIST
command which returns the detailed file listing in human readable format.
If pathname
is omited then the list of files in the current directory will be
returned otherwise it will the list of files on pathname
.
Parse result
You can parse the output of this command with
use std::str::FromStr;
use suppaftp::list::File;
let file: File = File::from_str("-rw-rw-r-- 1 0 1 8192 Nov 5 2018 omar.txt")
.ok()
.unwrap();
Runsourcepub fn nlst(&mut self, pathname: Option<&str>) -> FtpResult<Vec<String>>
pub fn nlst(&mut self, pathname: Option<&str>) -> FtpResult<Vec<String>>
Execute NLST
command which returns the list of file names only.
If pathname
is omited then the list of files in the current directory will be
returned otherwise it will the list of files on pathname
.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for FtpStream
impl Send for FtpStream
impl Sync for FtpStream
impl Unpin for FtpStream
impl UnwindSafe for FtpStream
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more