mattnenterprise / rust-ftp

FTP client for Rust
Apache License 2.0
182 stars 57 forks source link

help wanted: save all files by match pattern #41

Closed yackushevas closed 8 years ago

yackushevas commented 8 years ago

i don't figure out how save all files by wildcard, example **.txt*

for example from documentation we can save one file:

let result = ftp_stream.retr("test.txt", |stream| {
  let mut file = File::create("test.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(())
});
mattnenterprise commented 8 years ago

Unfortunately this isn't build into the FTP protocol. So it has to be built on top of it. To do that a NLST command needs to be given to list the contents of the directory. Then each of those items would need to be filtered based on the ending being ".txt". Once those are filtered we use the retr function to retrieve and save them. I have an example of doing this with a gist: https://gist.github.com/mattnenterprise/0bdf38cd87cffea070735bf1cd9bdd25

Hopefully that helps. Let me know if you need anything else.