# FTP: how to download recursivelly a whole directory - or at least get the information if a certain element is a dir?

**URL:** <https://discourse.julialang.org/t/ftp-how-to-download-recursivelly-a-whole-directory-or-at-least-get-the-information-if-a-certain-element-is-a-dir/101524>\
**Category:** General Usage\
**Tags:** question, ftpclient, ftp\
**Created:** [July 12, 2023, 9:34am UTC](https://discourse.julialang.org/t/ftp-how-to-download-recursivelly-a-whole-directory-or-at-least-get-the-information-if-a-certain-element-is-a-dir/101524 "2023-07-12T09:34:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [July 12, 2023, 9:34am UTC](https://discourse.julialang.org/t/ftp-how-to-download-recursivelly-a-whole-directory-or-at-least-get-the-information-if-a-certain-element-is-a-dir/101524/1 "2023-07-12T09:34:52Z")

</div>

Hello, I need to recursively download a directory from an anonymous FTP client:

```julia
using FTPClient
ftp_init();
ftp = FTP(hostname = "palantir.boku.ac.at", username = "anonymous", password = "")
cd(ftp, "Public/ImprovedForestCharacteristics")
pwd(ftp)
readdir(ftp)

```

In `ImprovedForestCharacteristics` I have then several subfolders with the data.

How can I download the whole `ImprovedForestCharacteristics` folder, or at least which of the outputs of `readdir` is a file or a directory in order to programmatically implement the recursion?  
The equivalent command with `wget` would be:  
`wget -r -nH --cut-dirs=2 -nc ftp://anonymous@palantir.boku.ac.at//Public/ImprovedForestCharacteristics`

(I am not using wget as I would prefer an OS independant solution)

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [July 12, 2023, 10:23am UTC](https://discourse.julialang.org/t/ftp-how-to-download-recursivelly-a-whole-directory-or-at-least-get-the-information-if-a-certain-element-is-a-dir/101524/2 "2023-07-12T10:23:49Z")

</div>

[from here](https://stackoverflow.com/questions/63268763/how-do-i-list-all-files-and-directories-in-a-directory-in-julia)

items = [item for item in walkdir(dir)]

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [July 12, 2023, 10:27am UTC](https://discourse.julialang.org/t/ftp-how-to-download-recursivelly-a-whole-directory-or-at-least-get-the-information-if-a-certain-element-is-a-dir/101524/3 "2023-07-12T10:27:59Z")

</div>

But this doesn’t extend to a remote FTP system.

I am going to use a customised `FTPClient.readdir()` function to report the info if an entry is a directory or not, but perhaps there is a better way…

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [July 12, 2023, 10:42am UTC](https://discourse.julialang.org/t/ftp-how-to-download-recursivelly-a-whole-directory-or-at-least-get-the-information-if-a-certain-element-is-a-dir/101524/4 "2023-07-12T10:42:41Z")

</div>

I have no way to test if [this](https://docs.juliahub.com/FilePathsBase/Efv1v/0.9.4/api/) acts as you ask on remote folders

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [July 13, 2023, 12:57pm UTC](https://discourse.julialang.org/t/ftp-how-to-download-recursivelly-a-whole-directory-or-at-least-get-the-information-if-a-certain-element-is-a-dir/101524/5 "2023-07-13T12:57:31Z")

</div>

Done it… the customised `FTPClient.reddir` function is [here](https://github.com/invenia/FTPClient.jl/issues/122) and the new `download_dir` function is [here](https://github.com/invenia/FTPClient.jl/issues/123).  
I have posted them as issues but I haven’t bothered to create a pull request as the `FTPClient` package doesn’t seem very maintained, so I didn’t want to wast time… if they are interested it will be a pleasure to make a pull request.

Also, while developing them I come across two nasty bugs in that package, that I have reported [here](https://github.com/invenia/FTPClient.jl/issues/120) and [here](https://github.com/invenia/FTPClient.jl/issues/121). Again, I don’t have really much hope they will be faced, but never says never…
