我正在 Java 中使用 Apache Commons-Net 库
我想要的是在客户端阶段设置 FTP 服务器的连接超时 使用java代码
示例:
如果我查看 FTP 服务器的 vsftpd.conf 设置文件,
有一个idle_session_timeout=600
设置
我想知道这个空闲超时是否可以通过FTP客户端使用java代码来控制
下面的方法,我试过了,但不是全部有效
FTPClient.setControlKeepAliveTimeout(sec);
FTPClient.setConnectTimeout(ms);
FTPClient.setDataTimeout(ms);
FTPClient.connect();
FTPClient.setSoTimeout(ms);
请帮助我:)
最佳答案
FTP 客户端无法控制 FTP 服务器的设置。
但是你问的看起来更像是 XY problem其中 X 可能是您想要阻止服务器关闭空闲连接,Y 是您提出的解决方案的想法:从客户端控制服务器超时。只是,这个解决方案行不通。
相反,您需要解决服务器关闭连接的真正原因:因为客户端没有 Activity 。这个问题可以简单地通过客户端与服务器交互来解决。这样就偶documented 。引用:
You should keep in mind that the FTP server may choose to prematurely close a connection if the client has been idle for longer than a given time period (usually 900 seconds). ... You may avoid server disconnections while the client is idle by periodically sending NOOP commands to the server.
关于java - FTP客户端可以控制FTP服务器超时设置吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57352335/