[ftputil] Issue with Hidden Directories
Stefan Schwarzer
sschwarzer at sschwarzer.net
Thu Oct 20 22:35:31 CEST 2005
Hi Alex
Thanks for your problem report!
On 2005-10-20 20:56, Alexander Michael wrote:
> I am attempting to use ftputil (version 2.0.3) with Python 2.4.1 to pull
> files from a data vendor's server [331-(220 pawn Microsoft FTP Service
> (Version 5.0).)], but ran into a small issue. Here's what the failure
> looks like:
>
> Traceback (most recent call last):
> File "updatefiles.py", line 210, in cli
> outgoingdir=ostools.nativepath(opts.outgoing_dir))
> File "updatefiles.py", line 128, in update
> ftp_update(basedir, host, proxy, outgoingdir)
> File "updatefiles.py", line 91, in ftp_update
> filenames = host.listdir('')
As with os.listdir, you should pass in "." (=FTPHost.curdir) for the
current directory.
> File "C:\Python24\Lib\site-packages\ftputil\ftputil.py", line 634, in
> listdir
> return self._stat.listdir(path)
> File "C:\Python24\Lib\site-packages\ftputil\ftp_stat.py", line 115, in
> listdir
> raise ftp_error.PermanentError("550 %s: no such directory" % path)
> PermanentError: 550 /johndoe: no such directory
>
> Looking around "C:\Python24\Lib\site-packages\ftputil\ftp_stat.py", line
> 115, I see:
>
> path = self._path.abspath(path)
> if not self._path.isdir(path):
> raise ftp_error.PermanentError("550 %s: no such directory" %
> path)
>
> I think the issue revolves around the fact the vendor has the FTP
> account setup so that I get dropped into a subdirectory (with the same
> name as my username), but the directory isn't visible one level up. As
> result, the lstat method fails to determine that path is a directory.
> After changing the above to be:
>
> path = self._path.abspath(path)
> if path != self._host.getcwd() and not self._path.isdir(path):
> raise ftp_error.PermanentError("550 %s: no such directory" %
> path)
>
> so that it doesn't fail for the current working directory, everything
> works great. I'm not sure if there is a better or more efficient way to
> be robust to this situation, but this worked for me. I am not sure if I
> can rest assured that the current working directory is in fact a
> directory, but it seems to make some sense.
I think your assumption is right, and as far as I see your change should
work though it seems a bit obscure. ;-) Let me think about if I put in
the next release. I think that's ok for you, considering the license,
isn't it?
Does anyone on the list see a problem with the patch?
> Thanks for making this useful module available (and under a nice license).
You're welcome :)
Best regards
Stefan
More information about the ftputil
mailing list