Ticket #5 (closed defect: invalid)
ftputil fails when server requires Windows-style slashes
| Reported by: | tephyr | Owned by: | schwa |
|---|---|---|---|
| Priority: | major | Milestone: | 2.1 |
| Component: | Library | Version: | 2.0.3 |
| Keywords: | windows, path, listdir | Cc: |
Description
Client (my system)
- Linux grig 2.6.12-9-amd64-generic #1 Mon Oct 10 13:27:39 BST 2005 x86_64
- GNU/Linux
- Python 2.4.2
Server
- probably Windows
- 220-Wildcat! FTP Service (v6.0.451.1 Sat, 28 Jan 2006 13:18:33 -0800) ready.
The problem
The server admin decided to switch the "format" setting from unix to dos, and of course did not tell me, so my script failed. Their tech support said:
"There could be 1 thing - another customer had the same problem - it has to do with the format we are using - I was using unix style and change to dos - that is probably it. See if there is a setting you can try on your ftp program that changes the format."
So I used the host.set_directory_format('ms') command, but ftputil still failed with this error on the host (my script enters the path - it's not generated by ftputil):
listdir('\\Quotes_Daily\\daily_stocks') command:
PermanentError: 550 /\Quotes_Daily\daily_stocks: no such directory
It appears that the path.isabs method fails because it thinks '\' is not a valid absolute path, because the ftp_path module always delegates the path functions to posixpath.
I got it working with the following changes to ftp_path.py:
# Import ntpath
import posixpath, ntpath
# force _Path.__init__ to use ntpath instead of posixpath
def __init__(self, host):
self._host = host
# delegate these to the `posixpath` module
pp = ntpath #posixpath
This obviously is a stopgap measure. The better solution would be for _Path.__init__ to check the host object for the directory format, and use posixpath or ntpath accordingly.
Notes
Stefan asked me to try this format: host.listdir('/Quotes_Daily/daily_stocks'), which did not work. Similar error to original.
