Opened 13 years ago

Closed 13 years ago

#19 closed defect (fixed)

If first listdir() call is on empty dir, ftputil assumes Unix style directory

Reported by: ssteiner Owned by: schwa
Priority: major Milestone: 2.2
Component: Library Version: 2.2b
Keywords: Cc: ssteiner@…

Description (last modified by schwa)

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

Change History (3)

comment:1 Changed 13 years ago by schwa

Description: modified (diff)
Status: newassigned

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.

comment:2 Changed 13 years ago by schwa

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

comment:3 Changed 13 years ago by ssteiner

Cc: ssteiner@… added
Resolution: fixed
Status: assignedclosed

Fixed in my test case. Thanks!

Note: See TracTickets for help on using tickets.