I am trying to get the name of all directories from an FTP server and store them hierarchically in a multidimensional list or dict
So, for example, a server that contains the following structure:
/www/
mysite.com
images
png
jpg
at the end of the script, give me a list, for example
['/www/'
['mysite.com'
['images'
['png'],
['jpg']
]
]
]
I tried using a recursive function: def traverse (dir): FTP.dir (dir, traverse)
FTP.dir returns strings in this format:
drwxr-xr-x 5 leavesc1 leavesc1 4096 Nov 29 20:52 mysite.com
so the line [56:] will give me only the directory name (mysite.com). I use this in a recursive function.
But I can’t make it work. I tried many different approaches and can't make it work. There are also many FTP errors (either the directory cannot be found - this is a logical problem, and sometimes unexpected errors returned by a server that does not leave a log, and I can’t debug it)
:
FTP-?