From e252713eb15b7308db084792cc30f9426159888f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=A2=D1=80=D0=B5?= =?UTF-8?q?=D0=B9=D0=BD=D0=B8=D1=81?= Date: Wed, 2 Dec 2015 15:06:05 +0200 Subject: [PATCH] ServerConn::openDataConn() recursively tries to use EPSV and PASV. --- ftp.go | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/ftp.go b/ftp.go index 34377b2..f822bd6 100644 --- a/ftp.go +++ b/ftp.go @@ -217,28 +217,18 @@ func (c *ServerConn) pasv() (port int, err error) { // openDataConn creates a new FTP data connection. func (c *ServerConn) openDataConn() (net.Conn, error) { - var port int - var err error + var ( + port int + err error + ) - // If features contains nat6 or EPSV => EPSV - // else -> PASV - _, nat6Supported := c.features["nat6"] - _, epsvSupported := c.features["EPSV"] - - if !nat6Supported && !epsvSupported { - port, _ = c.pasv() - } - if port == 0 { - port, err = c.epsv() - if err != nil { + if port, err = c.epsv(); err != nil { + if port, err = c.pasv(); err != nil { return nil, err } } - // 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", net.JoinHostPort(c.host, strconv.Itoa(port)), c.timeout) } // cmd is a helper function to execute a command and check for the expected FTP