Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to set client name #409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down