PASS command may be optional if the server answers 230 after issuing USER
This commit is contained in:
parent
a40f117d27
commit
7a3697af8c
8
ftp.go
8
ftp.go
@ -80,15 +80,21 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch code {
|
||||||
|
case StatusLoggedIn:
|
||||||
|
case StatusUserOK:
|
||||||
_, _, err = c.cmd(StatusLoggedIn, "PASS %s", password)
|
_, _, err = c.cmd(StatusLoggedIn, "PASS %s", password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
return errors.New(message)
|
||||||
|
}
|
||||||
|
|
||||||
// Switch to binary mode
|
// Switch to binary mode
|
||||||
_, _, err = c.cmd(StatusCommandOK, "TYPE I")
|
_, _, err = c.cmd(StatusCommandOK, "TYPE I")
|
||||||
|
Loading…
Reference in New Issue
Block a user