From 0f9f60bd5149d43e6431e8e1b87e51c755995c49 Mon Sep 17 00:00:00 2001 From: Ezequiel Moreno Date: Wed, 17 Feb 2016 12:25:04 -0300 Subject: [PATCH] Add configuration field. add DialWithConf builder. --- ftp.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ftp.go b/ftp.go index cae2f61..8b19f06 100644 --- a/ftp.go +++ b/ftp.go @@ -22,11 +22,15 @@ const ( EntryTypeLink ) +type Conf struct { + timeout time.Duration +} + // ServerConn represents the connection to a remote FTP server. type ServerConn struct { conn *textproto.Conn host string - timeout time.Duration + conf Conf 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 // an authenticated user. 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 { return nil, err } @@ -77,8 +86,8 @@ func DialTimeout(addr string, timeout time.Duration) (*ServerConn, error) { c := &ServerConn{ conn: conn, host: host, - timeout: timeout, features: make(map[string]string), + conf: conf, } _, _, err = c.conn.ReadResponse(StatusReady) @@ -242,7 +251,7 @@ func (c *ServerConn) openDataConn() (net.Conn, error) { // Build the new net address string 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