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

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

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)

from here

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

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…

I have no way to test if this acts as you ask on remote folders

Done it… the customised FTPClient.reddir function is here and the new download_dir function is here.
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 and here. Again, I don’t have really much hope they will be faced, but never says never…

1 Like