Skip to content

Commit dce4d3e

Browse files
committed
Use hostname for FTPS EPSV data connection
This allows FTPS to reuse the TLS session of the FSTP command connection for the data connection.
1 parent 1cc5b6e commit dce4d3e

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/main/java/org/apache/commons/net/ftp/FTPClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,10 +828,14 @@ protected void _parseExtendedPassiveModeReply(String reply) throws MalformedServ
828828
throw new MalformedServerReplyException("Could not parse extended passive host information.\nServer Reply: " + reply);
829829
}
830830
// in EPSV mode, the passive host address is implicit
831-
passiveHost = getRemoteAddress().getHostAddress();
831+
passiveHost = _resolveExtendedPassiveModeHost();
832832
passivePort = port;
833833
}
834834

835+
protected String _resolveExtendedPassiveModeHost() {
836+
return getRemoteAddress().getHostAddress();
837+
}
838+
835839
/**
836840
* Parses a reply.
837841
*

src/main/java/org/apache/commons/net/ftp/FTPSClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,5 +1119,14 @@ protected void sslNegotiation() throws IOException {
11191119
throw new SSLHandshakeException("Hostname doesn't match certificate");
11201120
}
11211121
}
1122+
1123+
@Override
1124+
protected String _resolveExtendedPassiveModeHost() {
1125+
if (_socket_ instanceof SSLSocket) {
1126+
return ((SSLSocket) _socket_).getSession().getPeerHost();
1127+
} else {
1128+
return super._resolveExtendedPassiveModeHost();
1129+
}
1130+
}
11221131
}
11231132

0 commit comments

Comments
 (0)