diff --git a/ftp.go b/ftp.go index 02136ae..f9c6cd1 100644 --- a/ftp.go +++ b/ftp.go @@ -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 }