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

sebastien s.thuriez at laposte.net
Mon Apr 7 11:01:30 EDT 2003


matt at teaphoo.fsnet.co.uk (Matt Russell) wrote in message news:<459f9b68.0304041432.3451f57b at posting.google.com>...

Hi to you all,


* For getting the listing of a directory, I do not feel any difference
in speed in between ftp.nlst ("/") and ftp.retrlines("LIST",
list.append). My connexion is extremly slow. This may explain why.
Also using nlst, I do not know which is a directory or a file. I have
trouble then to walk the directory structure in search for my file.

* I do not want to use the os.path.walk since this program send
several thread to each of the directory. I feel this recursive walk is
simple enough not to use os.path.thread.

* For names wich includes spaces caracters, I think that the advices
that you gave me will do the trick. I was just hoping for something
more general. But since I will work on a the same couple of servers it
will do the trick.

Thanks for yours quick responses.

Sebastien.



> I think FTP.nlst([ directory ])
> solves your problem.
> you may be able to use this method in conjunctio n with os.path.walk
> to achieve your goal.
> Matt
> 
> s.thuriez at laposte.net (sebastien) wrote in message news:<b1ab591.0304030143.52422a3e at posting.google.com>...
> > 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