Add configuration field.
add DialWithConf builder.
This commit is contained in:
parent
3e92923fa0
commit
0f9f60bd51
17
ftp.go
17
ftp.go
@ -22,11 +22,15 @@ const (
|
|||||||
EntryTypeLink
|
EntryTypeLink
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Conf struct {
|
||||||
|
timeout time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
// ServerConn represents the connection to a remote FTP server.
|
// ServerConn represents the connection to a remote FTP server.
|
||||||
type ServerConn struct {
|
type ServerConn struct {
|
||||||
conn *textproto.Conn
|
conn *textproto.Conn
|
||||||
host string
|
host string
|
||||||
timeout time.Duration
|
conf Conf
|
||||||
features map[string]string
|
features map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +63,12 @@ func Dial(addr string) (*ServerConn, error) {
|
|||||||
// It is generally followed by a call to Login() as most FTP commands require
|
// It is generally followed by a call to Login() as most FTP commands require
|
||||||
// an authenticated user.
|
// an authenticated user.
|
||||||
func DialTimeout(addr string, timeout time.Duration) (*ServerConn, error) {
|
func DialTimeout(addr string, timeout time.Duration) (*ServerConn, error) {
|
||||||
tconn, err := net.DialTimeout("tcp", addr, timeout)
|
return DialWithConf(addr, Conf{timeout: timeout})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DialWithConf is Dial plus configuration possibilities
|
||||||
|
func DialWithConf(addr string, conf Conf) (*ServerConn, error) {
|
||||||
|
tconn, err := net.DialTimeout("tcp", addr, conf.timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -77,8 +86,8 @@ func DialTimeout(addr string, timeout time.Duration) (*ServerConn, error) {
|
|||||||
c := &ServerConn{
|
c := &ServerConn{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
host: host,
|
host: host,
|
||||||
timeout: timeout,
|
|
||||||
features: make(map[string]string),
|
features: make(map[string]string),
|
||||||
|
conf: conf,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err = c.conn.ReadResponse(StatusReady)
|
_, _, err = c.conn.ReadResponse(StatusReady)
|
||||||
@ -242,7 +251,7 @@ func (c *ServerConn) openDataConn() (net.Conn, error) {
|
|||||||
// Build the new net address string
|
// Build the new net address string
|
||||||
addr := net.JoinHostPort(c.host, strconv.Itoa(port))
|
addr := net.JoinHostPort(c.host, strconv.Itoa(port))
|
||||||
|
|
||||||
return net.DialTimeout("tcp", addr, c.timeout)
|
return net.DialTimeout("tcp", addr, c.conf.timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmd is a helper function to execute a command and check for the expected FTP
|
// cmd is a helper function to execute a command and check for the expected FTP
|
||||||
|
Loading…
Reference in New Issue
Block a user