Is there a way to tell if the FTP server is active or passive in the Java web program?(有没有办法在 Java Web 程序中判断 FTP 服务器是主动的还是被动的?)
问题描述
我正在使用 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 服务器是主动的还是被动的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有没有办法在 Java Web 程序中判断 FTP 服务器是主


- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01