소스 검색

Fix EPSV for domains with multiple A entries.

We can not use the DNS name to open the data connection, as we might get
another IP than the current host from the DNS resolution.
Julien Laffaye 10 년 전
부모
커밋
b33f6e0005
1개의 변경된 파일5개의 추가작업 그리고 2개의 파일을 삭제
  1. 5 2
      ftp.go

+ 5 - 2
ftp.go

@@ -59,12 +59,15 @@ func Dial(addr string) (*ServerConn, error) {
 // It is generally followed by a call to Login() as most FTP commands require
 // It is generally followed by a call to Login() as most FTP commands require
 // an authenticated user.
 // an authenticated user.
 func DialTimeout(addr string, timeout time.Duration) (*ServerConn, error) {
 func DialTimeout(addr string, timeout time.Duration) (*ServerConn, error) {
-	host, _, err := net.SplitHostPort(addr)
+	tconn, err := net.DialTimeout("tcp", addr, timeout)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	tconn, err := net.DialTimeout("tcp", addr, timeout)
+	// Use the resolved IP address in case addr contains a domain name
+	// If we use the domain name, we might not resolve to the same IP.
+	remoteAddr := tconn.RemoteAddr().String()
+	host, _, err := net.SplitHostPort(remoteAddr)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}