6713809: FTP fails from multi-homed system

Binds the data socket to the same address as the control socket

Reviewed-by: michaelm
This commit is contained in:
Jean-Christophe Collet 2008-07-01 13:29:36 +02:00
parent 9f99870d74
commit 19fc7593d1

View File

@ -352,6 +352,9 @@ public class FtpClient extends TransferProtocolClient {
s = new Socket(Proxy.NO_PROXY);
} else
s = new Socket();
// Bind the socket to the same address as the control channel. This
// is needed in case of multi-homed systems.
s.bind(new InetSocketAddress(serverSocket.getLocalAddress(),0));
if (connectTimeout >= 0) {
s.connect(dest, connectTimeout);
} else {
@ -417,8 +420,10 @@ public class FtpClient extends TransferProtocolClient {
// since we can't accept a connection through SOCKS (yet)
// throw an exception
throw new FtpProtocolException("Passive mode failed");
} else
portSocket = new ServerSocket(0, 1);
}
// Bind the ServerSocket to the same address as the control channel
// This is needed for multi-homed systems
portSocket = new ServerSocket(0, 1, serverSocket.getLocalAddress());
try {
myAddress = portSocket.getInetAddress();
if (myAddress.isAnyLocalAddress())