問題描述
我正在使用 Apache-Commons-Net 庫.
I'm using the Apache-Commons-Net library.
我想知道 FTP 服務器是主動模式還是被動模式.
I want to know if the FTP server is active-mode or passive-mode.
Apache-Commons-Net 庫中有這樣的方法嗎?
Is there a method like that in the Apache-Commons-Net library?
(GetDataConnectionMode()
是Java中連接后告訴你連接模式的方法.我想在之前檢查Maud)
(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
推薦答案
正如@Erwin 已經評論的那樣,服務器不是處于主動或被動模式.服務器通常同時支持這兩種模式.
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.
另請閱讀我關于 FTP 連接模式的文章以及它們所需的網絡配置,以明白,這是關于什么的.
Read also my article on FTP connection modes and the network configuration needed for them, to understand, what this is about.
這篇關于有沒有辦法在 Java Web 程序中判斷 FTP 服務器是主動的還是被動的?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!