diff --git a/README.md b/README.md index 4181a8c..8488deb 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,6 @@ if err != nil { log.Fatal(err) } -err = c.SetUTF8() -if err != nil { - log.Error(err) -} - // Do something with the FTP conn if err := c.Quit(); err != nil { diff --git a/client_test.go b/client_test.go index 3e209c8..ea0fa81 100644 --- a/client_test.go +++ b/client_test.go @@ -31,11 +31,6 @@ func testConn(t *testing.T, disableEPSV bool) { t.Fatal(err) } - err = c.SetUTF8() - if err != nil { - t.Error(err) - } - err = c.NoOp() if err != nil { t.Error(err) diff --git a/conn_test.go b/conn_test.go index 11be24d..4b9d7a5 100644 --- a/conn_test.go +++ b/conn_test.go @@ -328,7 +328,7 @@ func openConn(t *testing.T, addr string, options ...DialOption) (*ftpMock, *Serv // Helper to close a client connected to a mock server func closeConn(t *testing.T, mock *ftpMock, c *ServerConn, commands []string) { - expected := []string{"FEAT", "USER", "PASS", "TYPE"} + expected := []string{"FEAT", "USER", "PASS", "TYPE", "OPTS"} expected = append(expected, commands...) expected = append(expected, "QUIT") diff --git a/ftp.go b/ftp.go index 54853ad..adcdf41 100644 --- a/ftp.go +++ b/ftp.go @@ -53,6 +53,7 @@ type dialOptions struct { explicitTLS bool conn net.Conn disableEPSV bool + disableUTF8 bool location *time.Location debugOutput io.Writer dialFunc func(network, address string) (net.Conn, error) @@ -176,6 +177,13 @@ func DialWithDisabledEPSV(disabled bool) DialOption { }} } +// DialWithDisabledUTF8 returns a DialOption that configures the ServerConn with UTF8 option disabled +func DialWithDisabledUTF8(disabled bool) DialOption { + return DialOption{func(do *dialOptions) { + do.disableUTF8 = disabled + }} +} + // DialWithLocation returns a DialOption that configures the ServerConn with specified time.Location // The location is used to parse the dates sent by the server which are in server's timezone func DialWithLocation(location *time.Location) DialOption { @@ -279,6 +287,11 @@ func (c *ServerConn) Login(user, password string) error { return err } + // Switch to UTF-8 + if !c.options.disableUTF8 { + err = c.setUTF8() + } + // If using implicit TLS, make data connections also use TLS if c.options.tlsConfig != nil { c.cmd(StatusCommandOK, "PBSZ 0") @@ -331,8 +344,8 @@ func (c *ServerConn) feat() error { return nil } -// SetUTF8 issues an "OPTS UTF8 ON" command. -func (c *ServerConn) SetUTF8() error { +// setUTF8 issues an "OPTS UTF8 ON" command. +func (c *ServerConn) setUTF8() error { if _, ok := c.features["UTF8"]; !ok { return nil }