This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Fix for urllib.ftpwrapper.retrfile() and none existing files
Type: Stage:
Components: Library (Lib) Versions: Python 2.6
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, orsenthil, pknirsch
Priority: normal Keywords: patch

Created on 2007-02-20 17:33 by pknirsch, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
urllib.diff pknirsch, 2007-02-20 17:33 Patch to fix urllib.ftpwrapper.retrfile()
Messages (5)
msg51901 - (view) Author: Phil Knirsch (pknirsch) Date: 2007-02-20 17:33
When trying to retrieve a none existing file using the urllib.ftpwrapper.retrfile() method the behaviour is that instead of an error message a valid hook is returned and you will recieve a 0 byte file.

The current behaviour tries to emulate what one typically sees with http servers and DirIndexes, which means:

1) Try to RETR the file.
2) If that fails, assume it is a directory and LIST it.

Unfortunately it doesn't actually check whether the directory actually exists.

The attached patch fixes this by remembering the current directory using the PWD command, then temporarily change to that directory and switch back to the previous working directory if it was successfull.

If not we raise an IO error, as the file could neither be opened (RETR) nor was it a directory.

That way the behaviour is even closer to what happens with http servers where we get a 404 when we try to access a none existing file or directory.

Storing the current directory and switching back to it in case of no error will also put the connection back in the proper state and directory, so no unexpected behaviour happens here.

The patch is against the current SVN repository at revision 53833.

Read ya, Phil
msg51902 - (view) Author: Phil Knirsch (pknirsch) Date: 2007-03-29 10:46
Anyone looking at this? ;)

Read ya, Phil
msg51903 - (view) Author: Phil Knirsch (pknirsch) Date: 2007-03-29 10:51
Oh, and the fix is ofc against the current tree, which would be python-2.6 i guess, so fixed that.

Read ya, Phil
msg51904 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2007-08-19 08:22
Yes, a useful patch. Verified and tested it. Works fine.
msg61277 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-01-20 12:18
Committed patch (added an additional try-finally) as r60135.
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44597
2008-01-20 12:18:38georg.brandlsetstatus: open -> closed
resolution: accepted
messages: + msg61277
nosy: + georg.brandl
2007-02-20 17:33:00pknirschcreate