Struct ftp::FtpStream [] [src]

pub struct FtpStream {
    // some fields omitted
}

Stream to interface with the FTP server. This interface is only for the command stream.

Methods

impl FtpStream
[src]

fn connect<A: ToSocketAddrs>(addr: A) -> Result<FtpStream>

Creates an FTP Stream.

fn login(&mut self, user: &str, password: &str) -> Result<()>

Log in to the FTP server.

fn cwd(&mut self, path: &str) -> Result<()>

Change the current directory to the path specified.

fn cdup(&mut self) -> Result<()>

Move the current directory to the parent directory.

fn pwd(&mut self) -> Result<String>

Gets the current directory

fn noop(&mut self) -> Result<()>

This does nothing. This is usually just used to keep the connection open.

fn mkdir(&mut self, pathname: &str) -> Result<()>

This creates a new directory on the server.

fn transfer_type(&mut self, file_type: FileType) -> Result<()>

Sets the type of file to be transferred. That is the implementation of TYPE command.

fn quit(&mut self) -> Result<()>

Quits the current FTP session.

fn get(&mut self, file_name: &str) -> Result<BufReader<DataStream>>

Retrieves the file name specified from the server. 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.

fn rename(&mut self, from_name: &str, to_name: &str) -> Result<()>

Renames the file from_name to to_name

fn retr<F>(&mut self, filename: &str, reader: F) -> Result<()> where F: Fn(&mut Read) -> Result<()>

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.

let result = conn.retr("take_this.txt", |stream| {
  let mut file = File::create("store_here.txt").unwrap();
  let mut buf = [0; 2048];

  loop {
    match stream.read(&mut buf) {
      Ok(0) => break,
      Ok(n) => file.write_all(&buf[0..n]).unwrap(),
      Err(err) => return Err(err)
    };
  }

  Ok(())
});

fn simple_retr(&mut self, file_name: &str) -> Result<Cursor<Vec<u8>>>

Simple way to retr a file from the server. This stores the file in memory.

fn rmdir(&mut self, pathname: &str) -> Result<()>

Removes the remote pathname from the server.

fn rm(&mut self, filename: &str) -> Result<()>

Remove the remote file from the server.

fn put<R: Read>(&mut self, filename: &str, r: &mut R) -> Result<()>

This stores a file on the server.

fn list(&mut self, pathname: Option<&str>) -> Result<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.

fn nlst(&mut self, pathname: Option<&str>) -> Result<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.

fn mdtm(&mut self, pathname: &str) -> Result<Option<DateTime<UTC>>>

Retrieves the modification time of the file at pathname if it exists. In case the file does not exist None is returned.

fn size(&mut self, pathname: &str) -> Result<Option<usize>>

Retrieves the size of the file in bytes at pathname if it exists. In case the file does not exist None is returned.

fn read_response(&mut self, expected_code: u32) -> Result<Line>

fn read_response_in(&mut self, expected_code: &[u32]) -> Result<Line>

Retrieve single line response

Trait Implementations

impl Debug for FtpStream
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.