From e987451f992dfcc1d8e6da58f436ef3a1d6adf4b Mon Sep 17 00:00:00 2001 From: Julien Laffaye Date: Tue, 18 Aug 2015 19:00:56 +0200 Subject: [PATCH] SplitHostPort before connecting to the remote. This, way, we dont have to cleanup the tcp connection if SplitHostPort fails. --- ftp.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ftp.go b/ftp.go index 2255b97..f178012 100644 --- a/ftp.go +++ b/ftp.go @@ -59,6 +59,11 @@ 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) { + host, _, err := net.SplitHostPort(addr) + if err != nil { + return nil, err + } + tconn, err := net.DialTimeout("tcp", addr, timeout) if err != nil { return nil, err @@ -66,11 +71,6 @@ func DialTimeout(addr string, timeout time.Duration) (*ServerConn, error) { conn := textproto.NewConn(tconn) - host, _, err := net.SplitHostPort(addr) - if err != nil { - conn.Close() - return nil, err - } c := &ServerConn{ conn: conn, host: host,