Add possibility to set client name

This commit is contained in:
m@rako.space 2024-12-20 17:53:01 +01:00
parent 1b970516f5
commit cbaf47e488

14
ftp.go
View File

@ -85,6 +85,7 @@ type dialOptions struct {
debugOutput io.Writer
dialFunc func(network, address string) (net.Conn, error)
shutTimeout time.Duration // time to wait for data connection closing status
clientName string
}
// Entry describes a file and is returned by List().
@ -178,6 +179,12 @@ func Dial(addr string, options ...DialOption) (*ServerConn, error) {
return c, nil
}
// DialWithName returns a DialOption that configures the ServerConn with specified client name
func DialWithName(name string) DialOption {
return DialOption{func(do *dialOptions) {
do.clientName = strings.TrimSpace(name)
}}
}
// DialWithTimeout returns a DialOption that configures the ServerConn with specified timeout
func DialWithTimeout(timeout time.Duration) DialOption {
@ -399,6 +406,13 @@ func (c *ServerConn) Login(user, password string) error {
}
}
// If name can be set
if _, nameSupported := c.features["CLNT"]; nameSupported && c.options.clientName != "" {
if _, _, err = c.cmd(StatusCommandOK, "CLNT " + c.options.clientName); err != nil {
return err
}
}
return err
}