FTP客户端可以控制FTP服务器超时设置吗? [英] Can the FTP client control FTP server time-out settings?
问题描述
我正在使用Java中的 Apache Commons-Net 库
I am using Apache Commons-Net library in Java
我想要的是在客户端阶段设置FTP服务器的连接超时 使用Java代码
What I want is to set the connection time-out of the FTP-server on the client stage using java-code
示例:
如果我查看FTP服务器的vsftpd.conf设置文件,
If I look at the FTP server's vsftpd.conf settings file,
有一个idle_session_timeout=600
设置
我想知道FTP客户端是否可以使用Java代码控制此空闲超时时间
I wonder if this idle time-out can be controlled by FTP-client using java code
下面的方法,我尝试过,但并非所有方法都有效
The method below, which I tried but not all worked
FTPClient.setControlKeepAliveTimeout(sec);
FTPClient.setConnectTimeout(ms);
FTPClient.setDataTimeout(ms);
FTPClient.connect();
FTPClient.setSoTimeout(ms);
请帮助我:)
推荐答案
FTP客户端无法控制FTP服务器的设置.
The FTP client cannot control the settings of the FTP server.
但是您要问的内容更像是 XY问题其中X可能是您想要的为防止服务器关闭空闲连接,您想出了一个解决方案,即Y:从客户端控制服务器超时.仅此解决方案不起作用.
But what you are asking looks more like an XY problem where X is probably that you want to prevent the server to close an idle connection an Y is the idea of a solution you came up with: controlling the servers timeout from the client side. Only, this solution will not work.
相反,您需要解决服务器关闭连接的真正原因:由于客户端没有活动.可以通过客户端与服务器交互来简单地解决该问题.甚至已记录一个>.引用:
Instead you need to tackle the real reason why the server is closing the connection: because of no activity from the client. This problem can be tackled simply by the client interacting with the server. This way is even documented. To cite:
请记住,如果客户端空闲时间超过给定时间段(通常为900秒),则FTP服务器可能会选择过早关闭连接. ...您可以通过定期向服务器发送NOOP命令来在客户端空闲时避免服务器断开连接.
这篇关于FTP客户端可以控制FTP服务器超时设置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!