Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
366 views
in Technique[技术] by (71.8m points)

java - Can the FTP client control FTP server time-out settings?

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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...