try to read the server response after a failed upload

if the upload failed we still need to try to read the server
response otherwise if the failure is not due to a connection problem,
for example the server denied the upload for quota limits, we miss
the response and we cannot use the connection to send other commands

Here is what happen before this patch:

C->S STOR test_file1.dat
S->C 150 Using transfer connection
S->C 550 Could not transfer file: denying write due to space limit

the client does not read the above 550 response and send the next command, so
the response for the STOR response will be readed as response for the next
command
This commit is contained in:
Nicola Murino 2020-07-30 14:52:42 +02:00
parent 13949d3891
commit 08a1e2e380

7
ftp.go
View File

@ -650,6 +650,11 @@ func (c *ServerConn) StorFrom(path string, r io.Reader, offset uint64) error {
_, err = io.Copy(conn, r)
conn.Close()
if err != nil {
// if the upload failed we still need to try to read the server
// response otherwise if the failure is not due to a connection problem,
// for example the server denied the upload for quota limits, we miss
// the response and we cannot use the connection to send other commands
c.conn.ReadResponse(StatusClosingDataConnection)
return err
}
@ -671,6 +676,8 @@ func (c *ServerConn) Append(path string, r io.Reader) error {
_, err = io.Copy(conn, r)
conn.Close()
if err != nil {
// see the comment for StorFrom above
c.conn.ReadResponse(StatusClosingDataConnection)
return err
}