Moving the set UTF-8 and binary modes out of the login method

This commit is contained in:
Warren Bailey 2017-05-31 14:47:53 +01:00
parent 5c7b901224
commit 2158f26dbb
No known key found for this signature in database
GPG Key ID: A0F1F14544B96D6E
3 changed files with 34 additions and 9 deletions

View File

@ -94,6 +94,14 @@ func TestMultiline(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
err = c.Binary()
if err != nil {
t.Fatal(err)
}
err = c.SetUTF8()
if err != nil {
t.Fatal(err)
}
c.Quit() c.Quit()

View File

@ -42,6 +42,16 @@ func testConn(t *testing.T, disableEPSV bool) {
t.Fatal(err) t.Fatal(err)
} }
err = c.Binary()
if err != nil {
t.Fatal(err)
}
err = c.SetUTF8()
if err != nil {
t.Fatal(err)
}
err = c.NoOp() err = c.NoOp()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@ -218,6 +228,16 @@ func TestConnIPv6(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
err = c.Binary()
if err != nil {
t.Fatal(err)
}
err = c.SetUTF8()
if err != nil {
t.Fatal(err)
}
_, err = c.List(".") _, err = c.List(".")
if err != nil { if err != nil {
t.Error(err) t.Error(err)

15
ftp.go
View File

@ -128,17 +128,14 @@ func (c *ServerConn) Login(user, password string) error {
default: default:
return errors.New(message) return errors.New(message)
} }
return nil
}
func (c *ServerConn) Binary() error {
// Switch to binary mode // Switch to binary mode
if _, _, err = c.cmd(StatusCommandOK, "TYPE I"); err != nil { if _, _, err := c.cmd(StatusCommandOK, "TYPE I"); err != nil {
return err return err
} }
// Switch to UTF-8
if err := c.setUTF8(); err != nil {
return err
}
return nil return nil
} }
@ -179,8 +176,8 @@ func (c *ServerConn) feat() error {
return nil return nil
} }
// setUTF8 issues an "OPTS UTF8 ON" command. // SetUTF8 issues an "OPTS UTF8 ON" command.
func (c *ServerConn) setUTF8() error { func (c *ServerConn) SetUTF8() error {
if _, ok := c.features["UTF8"]; !ok { if _, ok := c.features["UTF8"]; !ok {
return nil return nil
} }