只是为这些值添加一些说明(在手动测试了很多组合之后,并且只是提到这与DefaultFtpSessionFactory
在 apache 下使用的 spring 有关FTPClient
- 所以最后适用于那个):
import org.springframework.integration.ftp.session.DefaultFtpSessionFactory;
DefaultFtpSessionFactory factory = new DefaultFtpSessionFactory();
/**
* Controls 2 values:
* 1. protected abstract void connect(SocketAddress address, int timeout) throws IOException;
* --> controls timeout when opening socket connection. this one is by default 0 in java-code,
* but since OS is controlling this it has some default value - for me in win.
* it was ~20 seconds. If set to lower value it will be respected. If set >20 in my case,
* it always treats it as if 20 was set
* 2. _socket_.setSoTimeout(connectTimeout);
* --> controls timeout after socket is open (so if FTP server is not responding after
* socket is successfully connected). Default is unlimited so good to set to some sane value
* otherwise if no response from FTP Server, connection will hang. Overwrites setDefaultTimeout
* if already set - but only for this connection time (not after FTP server responds first time
* with some data).
*/
factory.setConnectTimeout((int) Duration.ofMinutes(1).toMillis());
/**
* Controls timeout after socket is open (so if FTP server is not responding after socket is
* successfully connected).(IF NOT ALREADY SET IN setConnectTimeout),
* but also controls timeout when reading data from socket after the connection has been made.
* So if FTP client sends "LIST /" command, and there is no answer from FTP server, without
* setting this it will hang (since default is 0). Set to some sane value
* (since server can actually be busy with creating listing of folders for longer time etc.).
*/
factory.setDefaultTimeout((int) Duration.ofMinutes(1).toMillis());
/**
* Controls how long to wait if there is a socket inactivity during FILE-related operations.
* E.g. if we start to download some file from FTP server, this timeout is respected.
* This is by default set to 0 (that is infinite wait). If set to 10 seconds, and there is at
* least some activity in communication (eg. every 9 seconds something is received) then there
* will be no timeout. Only if there is some delay/inactivity for longer than 10 seconds then
* there will be socketRead0 timeout exception. Should be set, since this is not affected by
* setConnectTimeout or setDefaultTimeout.
*/
factory.setDataTimeout((int) Duration.ofMinutes(1).toMillis());