Is there a way to tell if the FTP server is active or passive in the Java web program?

被刻印的时光 ゝ 提交于 2020-01-10 04:34:42

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/56266683/is-there-a-way-to-tell-if-the-ftp-server-is-active-or-passive-in-the-java-web-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!