Merge pull request #192 from drakkan/resp_error
try to read the server response after a failed upload
This commit is contained in:
commit
39e3779af0
17
ftp.go
17
ftp.go
@ -657,11 +657,14 @@ func (c *ServerConn) StorFrom(path string, r io.Reader, offset uint64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.Copy(conn, r)
|
||||
// if the upload fails 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.
|
||||
// So we don't check io.Copy error and we return the error from
|
||||
// ReadResponse so the user can see the real error
|
||||
io.Copy(conn, r)
|
||||
conn.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, _, err = c.conn.ReadResponse(StatusClosingDataConnection)
|
||||
return err
|
||||
@ -678,11 +681,9 @@ func (c *ServerConn) Append(path string, r io.Reader) error {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.Copy(conn, r)
|
||||
// see the comment for StorFrom above
|
||||
io.Copy(conn, r)
|
||||
conn.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, _, err = c.conn.ReadResponse(StatusClosingDataConnection)
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user