Java
Java
Send an FTP NOOP (Keep-Alive)
See more FTP Examples
Demonstrates the Chilkat Ftp2.Noop method, which sends the FTP NOOP command. It takes no arguments and succeeds only when the server returns a positive reply.
Background:
NOOP asks the server to do nothing and simply reply, which makes it the standard keep-alive: sending one periodically resets the server's idle timer so a long-running job does not lose its control connection between transfers. Because it exercises a real request/reply round trip, a successful NOOP is also firmer evidence the connection is alive than CheckConnection.Chilkat Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
// Demonstrates the Ftp2.Noop method, which sends the FTP NOOP command. It takes no arguments.
// The server must return a positive reply for the method to succeed.
CkFtp2 ftp = new CkFtp2();
ftp.put_Hostname("ftp.example.com");
ftp.put_Username("myFtpLogin");
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
ftp.put_Password("myPassword");
// Connect and log in (Connect performs both).
success = ftp.Connect();
if (success == false) {
System.out.println(ftp.lastErrorText());
return;
}
// NOOP does nothing on the server, but a successful reply confirms the control connection is
// still responsive -- useful as a keep-alive during an otherwise idle session.
success = ftp.Noop();
if (success == false) {
System.out.println(ftp.lastErrorText());
return;
}
System.out.println("NOOP acknowledged by the server.");
success = ftp.Disconnect();
if (success == false) {
System.out.println(ftp.lastErrorText());
return;
}
}
}