Merge pull request #14 from etix/master
Fix some issues with uncommon server behaviors
This commit is contained in:
commit
8fc92e7ea8
16
ftp.go
16
ftp.go
@ -80,14 +80,20 @@ func Connect(addr string) (*ServerConn, error) {
|
|||||||
// "anonymous"/"anonymous" is a common user/password scheme for FTP servers
|
// "anonymous"/"anonymous" is a common user/password scheme for FTP servers
|
||||||
// that allows anonymous read-only accounts.
|
// that allows anonymous read-only accounts.
|
||||||
func (c *ServerConn) Login(user, password string) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err = c.cmd(StatusLoggedIn, "PASS %s", password)
|
switch code {
|
||||||
if err != nil {
|
case StatusLoggedIn:
|
||||||
return err
|
case StatusUserOK:
|
||||||
|
_, _, err = c.cmd(StatusLoggedIn, "PASS %s", password)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return errors.New(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to binary mode
|
// Switch to binary mode
|
||||||
@ -477,7 +483,7 @@ func (r *response) Read(buf []byte) (int, error) {
|
|||||||
// Close implements the io.Closer interface on a FTP data connection.
|
// Close implements the io.Closer interface on a FTP data connection.
|
||||||
func (r *response) Close() error {
|
func (r *response) Close() error {
|
||||||
err := r.conn.Close()
|
err := r.conn.Close()
|
||||||
_, _, err2 := r.c.conn.ReadCodeLine(StatusClosingDataConnection)
|
_, _, err2 := r.c.conn.ReadResponse(StatusClosingDataConnection)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
err = err2
|
err = err2
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user