问题
I am using Apache Commons-Net library in Java
What I want is to set the connection time-out of the FTP-server on the client stage using java-code
example :
If I look at the FTP server's vsftpd.conf settings file,
there is a idle_session_timeout=600
setting
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);
Please help me :)
回答1:
The FTP client cannot control the settings of the FTP server.
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:
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.
来源:https://stackoverflow.com/questions/57352335/can-the-ftp-client-control-ftp-server-time-out-settings