Hi,
I've the following problem (using a FTP account on sharefile.com). The directory is well created but mkdir() raises a FTPOSError.
>>> ftp.mkdir("/foo")
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/path/to/ftputil/ftputil.py", line 622, in mkdir
self._robust_ftp_command(command, path)
File "/path/to/ftputil/ftputil.py", line 587, in _robust_ftp_command
return command(self, tail)
File "/path/to/ftputil/ftputil.py", line 621, in command
return ftp_error._try_with_oserror(self._session.mkd, path)
File "/path/to/ftputil/ftp_error.py", line 149, in _try_with_oserror
raise FTPOSError(*exc.args)
FTPOSError: 250 Created '/foo'.
Debugging info: ftputil 2.6, Python 2.7.3rc2 (linux2)
Thanks.
Thanks for the report.
This looks weird. The server seems to give a status code of 250 which actually doesn't stand for an error condition but a successful operation. Since ftputil only calls
ftplib.FTP.mkd
and "translates" raised exceptions to ftputil's, this might point to a bug in ftplib. Please try the directftplib
call (with the same Python version),import ftplib ftp = ftplib.FTP(host, user, password) ftp.mkd("/foo")
and tell me what you get. Make sure the directory you're trying to create doesn't exist before the call.
By the way, I saw you classfied the problem as "blocker", but I think there are workarounds that should change this to at most "major".
One approach is to use a derived class like this (beware, untested code):
class MyFTPHost(ftputil.FTPHost): def mkdir(self, path, mode=None): try: super(MyFTPHost, self).mkdir(path, mode) except ftputil.ftp_error.FTPOSError, exc: if "250 Created " in str(exc): pass else: raise
Thanks for the answer and the derived class. I guess I'll have to use such a workaround.
FYI, I did a test using ftplib.FTP...
>>> ftp.mkd("foo") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/path/to/python2.7/ftplib.py", line 559, in mkd return parse257(resp) File "/path/to/python2.7/ftplib.py", line 832, in parse257 raise error_reply, resp ftplib.error_reply: 250 Created '/foo'.
PS: I let you take proper action with this ticket.
Replying to ftputiluser:
Thanks for the answer and the derived class. I guess I'll have to use such a workaround.
FYI, I did a test using ftplib.FTP...
[...]
Thanks for the check. I did a web search and found this question and answer: http://stackoverflow.com/questions/3463033/why-is-a-success-message-considered-an-error-in-ftplib
- So to me this looks like a server bug.
PS: I let you take proper action with this ticket.
As far as ftputil is concerned, an "invalid" status seems appropriate to me. :-)
By the way, I see you're using ftputil 2.6. You may want to use version 2.7.1, which contains an improvement and a bugfix (see the Download page). These changes may not be relevant for you, though.