Sfoglia il codice sorgente

SplitHostPort before connecting to the remote.

This, way, we dont have to cleanup the tcp connection if SplitHostPort fails.
Julien Laffaye 10 anni fa
parent
commit
e987451f99
1 ha cambiato i file con 5 aggiunte e 5 eliminazioni
  1. 5 5
      ftp.go

+ 5 - 5
ftp.go

@@ -59,18 +59,18 @@ 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)
+	host, _, err := net.SplitHostPort(addr)
 	if err != nil {
 		return nil, err
 	}
 
-	conn := textproto.NewConn(tconn)
-
-	host, _, err := net.SplitHostPort(addr)
+	tconn, err := net.DialTimeout("tcp", addr, timeout)
 	if err != nil {
-		conn.Close()
 		return nil, err
 	}
+
+	conn := textproto.NewConn(tconn)
+
 	c := &ServerConn{
 		conn:     conn,
 		host:     host,