From 7a3697af8c84ac6e2a47853793e3e5781b7e72f1 Mon Sep 17 00:00:00 2001 From: Ludovic Fauvet Date: Tue, 18 Feb 2014 12:57:01 +0100 Subject: [PATCH 1/2] PASS command may be optional if the server answers 230 after issuing USER --- ftp.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ftp.go b/ftp.go index 93d7dfa..f535ac3 100644 --- a/ftp.go +++ b/ftp.go @@ -80,14 +80,20 @@ func Connect(addr string) (*ServerConn, error) { // "anonymous"/"anonymous" is a common user/password scheme for FTP servers // that allows anonymous read-only accounts. func (c *ServerConn) Login(user, password string) error { - _, _, err := c.cmd(StatusUserOK, "USER %s", user) + code, message, err := c.cmd(-1, "USER %s", user) if err != nil { return err } - _, _, err = c.cmd(StatusLoggedIn, "PASS %s", password) - if err != nil { - return err + switch code { + case StatusLoggedIn: + case StatusUserOK: + _, _, err = c.cmd(StatusLoggedIn, "PASS %s", password) + if err != nil { + return err + } + default: + return errors.New(message) } // Switch to binary mode From fb61796944cb6335050b09809f18c078ae853190 Mon Sep 17 00:00:00 2001 From: Ludovic Fauvet Date: Tue, 18 Feb 2014 16:51:07 +0100 Subject: [PATCH 2/2] Handle multi-line 226 status code --- ftp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftp.go b/ftp.go index f535ac3..673a5ae 100644 --- a/ftp.go +++ b/ftp.go @@ -483,7 +483,7 @@ func (r *response) Read(buf []byte) (int, error) { // Close implements the io.Closer interface on a FTP data connection. func (r *response) Close() error { err := r.conn.Close() - _, _, err2 := r.c.conn.ReadCodeLine(StatusClosingDataConnection) + _, _, err2 := r.c.conn.ReadResponse(StatusClosingDataConnection) if err2 != nil { err = err2 }