[ftputil] [BUG] .close() on FTP file may result in exception
Stefan Schwarzer
sschwarzer at sschwarzer.net
Wed Jul 26 10:34:56 CEST 2006
Hello Mikhail
Thanks for your report. (Shouldn't we move it to the bug tracker?
Do you want an account?)
On 2006-07-26 07:44, Mikhail Gusarov wrote:
> If you open file on FTP for reading and close it before reading EOF
> (actually, when server still has data to write to data stream),
> FTPIOException will be raised, because FTP server will report error
> 426.
>
> Testcase is attached.
>
> import ftputil
>
> host = ftputil.FTPHost('debian.nsu.ru', 'anonymous', '')
> f = host.file('mirrors/ftp.fi.debian.org/debian/doc/mailing-lists.txt')
> f.close()
This code doesn't throw an exception here, just as I tried it.
RFC 959 [1], which describes the file transfer protocol,
discusses the status code 426 like this:
"""
ABORT (ABOR)
This command tells the server to abort the previous FTP
service command and any associated transfer of data. The
abort command may require "special action", as discussed in
the Section on FTP Commands, to force recognition by the
server. No action is to be taken if the previous command
has been completed (including data transfer). The control
connection is not to be closed by the server, but the data
connection must be closed.
There are two cases for the server upon receipt of this
command: (1) the FTP service command was already completed,
or (2) the FTP service command is still in progress.
In the first case, the server closes the data connection
(if it is open) and responds with a 226 reply, indicating
that the abort command was successfully processed.
In the second case, the server aborts the FTP service in
progress and closes the data connection, returning a 426
reply to indicate that the service request terminated
abnormally. The server then sends a 226 reply,
indicating that the abort command was successfully
processed.
"""
Your's is the second case because the connection is aborted and
the status code sent by the server.
Which other FTP commands were running or had previously run when
the exception occured? It may be a mistake on your side, a server
bug, - or in fact a bug in ftputil (e. g. not correctly cleaning
up children sessions under certain circumstances, so you run in
trouble the _next_ time you use this child [2]). Therefore, I
would like to get more information on the context in which the
bug appears. Many thanks in advance. :-)
[1] http://www.ietf.org/rfc/rfc959.txt
[2] Using FTP file-like objects in ftputil creates new FTP
sessions behind the scenes. Those sessions are reused after
an FTPFile object has been closed.
Stefan
More information about the ftputil
mailing list