Walkdir & ftp - is this possible

Hi,

I currently use the ftp crate to clone a directory from a location on an ftp server. The ftp crate has options for getting a directory listing so I created a recursive function to scan through all directories. This appears to work well, but I am wondering if it is possible to use the walkdir crate to do this instead?

I have tested walkdir on my local filesystem and it works great but I am wondering if there is someway to use it with an instance of an ftp client? I suspect that this is not possible (since walkdir seems to expect a path reference) but I thought I would ask to see if anyone has any ideas. Below are some snippets for how I am using the ftp crate.

Thanks.

let mut client = FtpStream::connect(&address)?;
client.login("user", "pass")?;

//change to remote directory
client.cwd(&remote_directory)?;

//get list of directories and files as a vector
let contents = client.list(Some("./"))?;

walkdir is tightly coupled with platform specific syscalls for obtaining directory listings. It is not a generic library that lets those things be pluggable, so I don't think what you want to do is possible, if I'm understanding you correctly. (I'm not 100% sure that I am.)

Thanks BurntSushi.

I was basically looking to use WalkDir to recursively list the contents of a location on an ftp server. I had an intuition that it would not be possible but thought I'd ask.

I have implemented a solution myself using a simple recursive function that gets the directory/file listings of the current working directory on the ftp server and drills into each sub directory etc. but was wondering if I could use walkdir for this, instead of reinventing the wheel.

Thanks for your reply (and also for walkdir :slight_smile: )

If you want to use the walkdir crate you would need to mount the FTP server to a directory on your computer's file system (e.g. like in this article).

I'm guessing that isn't ideal for your use case though because it would affect the OS and at that point you could just use cp -r from a terminal.

Preferences may vary, but I'd prefer to write my own 50-line recursive function than pull in a 2500-line dependency.