always return the ReadResponse error after an upload

This commit is contained in:
Nicola Murino 2020-08-06 16:41:36 +02:00
parent 08a1e2e380
commit 4a68979b89

22
ftp.go
View File

@ -647,16 +647,14 @@ func (c *ServerConn) StorFrom(path string, r io.Reader, offset uint64) error {
return err return err
} }
_, err = io.Copy(conn, r) // if the upload fails we still need to try to read the server
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, // response otherwise if the failure is not due to a connection problem,
// for example the server denied the upload for quota limits, we miss // for example the server denied the upload for quota limits, we miss
// the response and we cannot use the connection to send other commands // the response and we cannot use the connection to send other commands.
c.conn.ReadResponse(StatusClosingDataConnection) // So we don't check io.Copy error and we return the error from
return err // ReadResponse so the user can see the real error
} io.Copy(conn, r)
conn.Close()
_, _, err = c.conn.ReadResponse(StatusClosingDataConnection) _, _, err = c.conn.ReadResponse(StatusClosingDataConnection)
return err return err
@ -673,13 +671,9 @@ func (c *ServerConn) Append(path string, r io.Reader) error {
return err return err
} }
_, err = io.Copy(conn, r)
conn.Close()
if err != nil {
// see the comment for StorFrom above // see the comment for StorFrom above
c.conn.ReadResponse(StatusClosingDataConnection) io.Copy(conn, r)
return err conn.Close()
}
_, _, err = c.conn.ReadResponse(StatusClosingDataConnection) _, _, err = c.conn.ReadResponse(StatusClosingDataConnection)
return err return err