问题描述
我正在使用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服务器是主动还是被动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!