# Walkdir & ftp - is this possible

**URL:** <https://users.rust-lang.org/t/walkdir-ftp-is-this-possible/58528>\
**Category:** help\
**Created:** [April 17, 2021, 3:39pm UTC](https://users.rust-lang.org/t/walkdir-ftp-is-this-possible/58528 "2021-04-17T15:39:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![djme](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@djme](https://users.rust-lang.org/u/djme)\
**Post date:** [April 17, 2021, 3:39pm UTC](https://users.rust-lang.org/t/walkdir-ftp-is-this-possible/58528/1 "2021-04-17T15:39:32Z")

</div>

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("./"))?;

---

<div class="post-metadata">

**Author:** ![BurntSushi](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/burntsushi/32/135_2.png) [@BurntSushi](https://users.rust-lang.org/u/BurntSushi)\
**Post date:** [April 17, 2021, 4:25pm UTC](https://users.rust-lang.org/t/walkdir-ftp-is-this-possible/58528/2 "2021-04-17T16:25:13Z")

</div>

`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.)

---

<div class="post-metadata">

**Author:** ![djme](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@djme](https://users.rust-lang.org/u/djme)\
**Post date:** [April 17, 2021, 6:26pm UTC](https://users.rust-lang.org/t/walkdir-ftp-is-this-possible/58528/3 "2021-04-17T18:26:35Z")

</div>

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 🙂 )

---

<div class="post-metadata">

**Author:** ![Michael-F-Bryan](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/michael-f-bryan/32/28749_2.png) [@Michael-F-Bryan](https://users.rust-lang.org/u/Michael-F-Bryan)\
**Post date:** [April 18, 2021, 6:37am UTC](https://users.rust-lang.org/t/walkdir-ftp-is-this-possible/58528/4 "2021-04-18T06:37:25Z")

</div>

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](https://linuxconfig.org/mount-remote-ftp-directory-host-locally-into-linux-filesystem)).

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.

> [@djme](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [July 17, 2021, 6:38am UTC](https://users.rust-lang.org/t/walkdir-ftp-is-this-possible/58528/5 "2021-07-17T06:38:20Z")

</div>

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
