[ftputil] Re: ftputil

Stefan Schwarzer sschwarzer at sschwarzer.net
Sat Jan 8 19:32:06 MET 2005


Hello Philippe!

[sent to the list with Philippe's consent]

On Saturday 08 January 2005 02:23, Philippe Strauss wrote:
> I'm trying to delete an entire tree of files on a remote ftp
> server, using your nice ftputil package,

Thanks :-)

> but the following code
> chokes on a file named .htaccess, listdir ignore it.

I just tested three different FTP accounts by logging in with a
command-line FTP client. With typing `dir`, on two servers I saw the
files with a leading dot, but on one not. Maybe it's an FTP server
configuration issue.

> I've spent quite some try understanding _dir logic but failed :)

Which part don't you understand? I do _not_ ask to imply you are
stupid ;) but how I could possibly improve the code so it's better
understandable.

> Where is the DIR, LIST commande sent,

The code uses the `dir` method on the contained `_session` object, in
`_dir`'s line

ftp_error._try_with_oserror(self._session.dir, tail, callback)

`_session` is an object of class `FTP` in Python's `ftplib` module.

`ftplib.FTP.dir`'s documentation reads

"""
dir(argument[, ...])
    Produce a directory listing as returned by the "LIST" command,
    printing it to standard output. The optional argument is a
    directory to list (default is the current server directory).
    Multiple arguments can be used to pass non-standard options to
    the "LIST"command. If the last argument is a function, it is used
    as a callback function as for retrlines(); the default prints to
    sys.stdout. This method returns None.
"""

I investigated this and came up with the attached patch (two lines
changed in `FTPHost._dir`). For me, it works for the one FTP server
who missed the dot file. Please try the patch and tell me if it
works.

> I would need to add a -a option to it?

I even didn't know of this -a option. Possibly this isn't standard,
but rather server-dependent. Perhaps it only works for Unix servers.
Do you know more?

Do you have any objections to have this reply also posted to
ftputil's mailing list? So it may be a help for other users, too.

Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ftputil-a.patch
Type: text/x-diff
Size: 1026 bytes
Desc: not available
Url : http://codespeak.net/pipermail/ftputil/attachments/20050108/87c5318b/ftputil-a.bin


More information about the ftputil mailing list