FTP : get dir name with space caracters embedded + is ther something quicker than LIST

sebastien s.thuriez at laposte.net
Thu Apr 3 04:43:33 EST 2003


Hi ,

I have 2 problems regarding FTP methods.


My GOAL :
---------

I am looking for a specific file on a huge ftp server. The structure
of the ftp server is not known. I have to determine which are
directories and which are files so that it can recursively go into the
subdirectories to scan the files (it is multi threaded).

It is working well but I have 2 problems.


 My trouble :
-----------------

It am using the ftp.retrlines('LIST',liste.append)
and analyse which one are directories since they have the letter d at
the beginning of the line.

1) The LIST METHOD IS EXTREMLY SLOW !!!

In certain directories there is thousand of file and the LIST method
is extremely slow.
It works but is there other method to get the directories without
having to do a LIST ?

2) DIRECTORY NAME WITH SPACES  

LIST is slow but it works. One other problem is the directory name in
which there is spaces : like
"data file today".
 I can do a :
elements= line.split(" "), 

but the data before my directory name has not the same format : for
example :

.....
may 22   2001     name of directory
mar 15    02:00   other directory name
.....

I do not know how to get the directory name simply.

One method would be to get a len(elements) and if len(elements) > 9
for example on my server. All the last elements would be part of
directory name. It is not so clean since it may depend on the FTP
server configuration.

Do you have any idea ?

Thanks for having taken the time to read my mail.

Sebastien.




More information about the Python-list mailing list