Browse Source

ServerConn::openDataConn() recursively tries to use EPSV and PASV.

Сергей Трейнис 10 years ago
parent
commit
e252713eb1
1 changed files with 7 additions and 17 deletions
  1. 7 17
      ftp.go

+ 7 - 17
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
-
-	//  If features contains nat6 or EPSV => EPSV
-	//  else -> PASV
-	_, nat6Supported := c.features["nat6"]
-	_, epsvSupported := c.features["EPSV"]
+	var (
+		port int
+		err  error
+	)
 
-	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