Make "OPTS UTF8 ON" optional (#172)
This commit is contained in:
parent
b9f3ade291
commit
60012218fd
@ -26,6 +26,11 @@ if err != nil {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = c.SetUTF8()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Do something with the FTP conn
|
// Do something with the FTP conn
|
||||||
|
|
||||||
if err := c.Quit(); err != nil {
|
if err := c.Quit(); err != nil {
|
||||||
|
63
ftp.go
63
ftp.go
@ -279,9 +279,6 @@ func (c *ServerConn) Login(user, password string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to UTF-8
|
|
||||||
err = c.setUTF8()
|
|
||||||
|
|
||||||
// If using implicit TLS, make data connections also use TLS
|
// If using implicit TLS, make data connections also use TLS
|
||||||
if c.options.tlsConfig != nil {
|
if c.options.tlsConfig != nil {
|
||||||
c.cmd(StatusCommandOK, "PBSZ 0")
|
c.cmd(StatusCommandOK, "PBSZ 0")
|
||||||
@ -334,36 +331,6 @@ func (c *ServerConn) feat() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// setUTF8 issues an "OPTS UTF8 ON" command.
|
|
||||||
func (c *ServerConn) setUTF8() error {
|
|
||||||
if _, ok := c.features["UTF8"]; !ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
code, message, err := c.cmd(-1, "OPTS UTF8 ON")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Workaround for FTP servers, that does not support this option.
|
|
||||||
if code == StatusBadArguments {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// The ftpd "filezilla-server" has FEAT support for UTF8, but always returns
|
|
||||||
// "202 UTF8 mode is always enabled. No need to send this command." when
|
|
||||||
// trying to use it. That's OK
|
|
||||||
if code == StatusCommandNotImplemented {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if code != StatusCommandOK {
|
|
||||||
return errors.New(message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// epsv issues an "EPSV" command to get a port number for a data connection.
|
// epsv issues an "EPSV" command to get a port number for a data connection.
|
||||||
func (c *ServerConn) epsv() (port int, err error) {
|
func (c *ServerConn) epsv() (port int, err error) {
|
||||||
_, line, err := c.cmd(StatusExtendedPassiveMode, "EPSV")
|
_, line, err := c.cmd(StatusExtendedPassiveMode, "EPSV")
|
||||||
@ -564,6 +531,36 @@ func (c *ServerConn) List(path string) (entries []*Entry, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetUTF8 issues an "OPTS UTF8 ON" command.
|
||||||
|
func (c *ServerConn) SetUTF8() error {
|
||||||
|
if _, ok := c.features["UTF8"]; !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
code, message, err := c.cmd(-1, "OPTS UTF8 ON")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Workaround for FTP servers, that does not support this option.
|
||||||
|
if code == StatusBadArguments {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// The ftpd "filezilla-server" has FEAT support for UTF8, but always returns
|
||||||
|
// "202 UTF8 mode is always enabled. No need to send this command." when
|
||||||
|
// trying to use it. That's OK
|
||||||
|
if code == StatusCommandNotImplemented {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if code != StatusCommandOK {
|
||||||
|
return errors.New(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// ChangeDir issues a CWD FTP command, which changes the current directory to
|
// ChangeDir issues a CWD FTP command, which changes the current directory to
|
||||||
// the specified path.
|
// the specified path.
|
||||||
func (c *ServerConn) ChangeDir(path string) error {
|
func (c *ServerConn) ChangeDir(path string) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user