I'm using the Apache-Commons-Net library.
I want to know if the FTP server is active-mode or passive-mode.
Is there a method like that in the Apache-Commons-Net library?
(GetDataConnectionMode()
is a method that tells you the connected mode after connecting in Java. I want to check Maud before)
private FTPClient ftp;
// the code I want
if(active){
ftp.enterLocalActiveMode();
}else{
ftp.enterLocalPassiveMode();
}
// Apply active mode or passive mode to the environment of the server for oneself
As @Erwin already commented, servers are not in active or passive mode. Servers usually support both modes at the same time.
A mode that you need to use, typically depends on a configuration of the network between you and the server, not on some "switch" on the server. There's hardly any way to detect that.
All you can do is to try one mode and fallback to the other if the first mode fails. In general, you should start with the passive mode, as that tends to work more often.
Read also my article on FTP connection modes and the network configuration needed for them, to understand, what this is about.