Add possibility to set client name
This commit is contained in:
parent
1b970516f5
commit
cbaf47e488
14
ftp.go
14
ftp.go
@ -85,6 +85,7 @@ type dialOptions struct {
|
|||||||
debugOutput io.Writer
|
debugOutput io.Writer
|
||||||
dialFunc func(network, address string) (net.Conn, error)
|
dialFunc func(network, address string) (net.Conn, error)
|
||||||
shutTimeout time.Duration // time to wait for data connection closing status
|
shutTimeout time.Duration // time to wait for data connection closing status
|
||||||
|
clientName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entry describes a file and is returned by List().
|
// Entry describes a file and is returned by List().
|
||||||
@ -178,6 +179,12 @@ func Dial(addr string, options ...DialOption) (*ServerConn, error) {
|
|||||||
|
|
||||||
return c, nil
|
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
|
// DialWithTimeout returns a DialOption that configures the ServerConn with specified timeout
|
||||||
func DialWithTimeout(timeout time.Duration) DialOption {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user