有没有办法在 Java Web 程序中判断 FTP 服务器是主动的还是被动的? [英] Is there a way to tell if the FTP server is active or passive in the Java web program?

查看:30
本文介绍了有没有办法在 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 服务器是主动的还是被动的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆