Search code examples
javaftpftp-clientapache-commons-net

FTPClient - Send Noop to a FTP server in a stream method


I'm using FTPClient (Apache Commons Net)

I know that FTPClient provides two methods to avoid the idle state of the FTP server:

  1. ftpClient.setControlKeepAliveTimeout(300) – Send a noop every five minutes
  2. ftpClient.sendNoOp() – send a noop a one-time event

I tried to use setControlKeepAliveTimeout()

But the official FTPClient document On setControlKeepAliveTimeout....

Please note: this does not apply to the methods where the user is responsible for writing or reading the data stream, i.e. retrieveFileStream(String), storeFileStream*(String) and the other xxxFileStream methods

My program uses only retrieveFileStream, which is not applied to setControlKeepAliveTimeout .

Is there no way to operate the noop repeatedly in a stream method, not a one-time event, like a sendNoOp?


Solution

  • There's nothing that will do it for you, the comment you have quoted is clear about that.

    You have to code it yourself:
    Read the stream and while doing that, in regular intervals, call the FTPClient.sendNoOp.