I am trying to to get all directories\' name from an FTP server and store them in hierarchical order in a multidimensional list or dict
So for example, a server that
You're not going to like this, but "it depends on the server" or, more accurately, "it depends on the output format of the server".
Different servers can be set to display different output, so your initial proposal is bound to failure in the general case.
The "naive and slow implementation" above will cause enough errors that some FTP servers will cut you off (which is probably what happened after about 7 of them...).