~sschwarzer/ftputil#19: 
If first listdir() call is on empty dir, ftputil assumes Unix style directory

import ftputil
h = ftputil.FTPHost( somehost,'anonymous','anonymous')
h.listdir(".")     # If this directory is empty, it uses the one chance to change the parser
                   # the directory's empty so the parser thinks all is well
                   # and that you're on a Unix system
h.chdir('some/other/directory')
h.listdir(".")     # If this is a Windows system, and the directory 
                   # has files in it, this raises a ParserError

There are a few possible solutions to this, as far as I can tell.

When I originally encountered the issue where ftputil didn't handle Windows directories at all I used the 'site dirstyle' to get the Windows server to us Unix style directory listings.

I think this would work in the current scheme:

if there's a parse error using the Unix parser
  set 'parser switched' flag
  Tell the server to switch to Unix flavor with the 'site dirstyle' command
  If the server says 'ok, it's unix now'
     retry the command
  else 
    if the server says 'Windows' (i.e. it was already in Unix mode)
       'site dirstyle' back to Unix
       retry the command
   else (the server didn't understand 'site dirstyle')
      switch to the Windows parser
      retry command

This seems the simplest and most foolproof way, to me.

I probably don't have the code around any more but if you'd like me to recreate it, I will...I don't remember it taking all that long to code in the first place.

S

Status
RESOLVED FIXED
Submitter
ssteiner (unverified)
Assigned to
No-one
Submitted
17 years ago
Updated
17 years ago
Labels
bug library

schwa (unverified) 17 years ago · edit

Thanks for the report. After your private mail I've looked into this and extended the algorithm which has been used until now. If you have a ​Subversion client installed, please check out the trunk,

svn checkout -r649 svn://ftputil.sschwarzer.net/ftputil/trunk ftputil_test

and test if the error is gone (it should unless my unit test for it is wrong ;-) ). You may have to set PYTHONPATH, so that the changed code is found, not an already installed ftputil version. (Because I also changed some interaction code between the modules, you can't just replace ftp_stat.py with the newer version.)

If you don't have a Subversion client, tell me, and I'll put together a tarball.

schwa (unverified) 17 years ago · edit

Please download ftputil 2.2b2 to see if the bug is fixed there.

ssteiner (unverified) 17 years ago · edit

Fixed in my test case. Thanks!

Register here or Log in to comment, or comment via email.