Sample code for 30+ languages & platforms
Java

Set a Remote FTP File's Last-Modified Time

See more FTP Examples

Demonstrates the Chilkat Ftp2.SetRemoteFileDateTimeStr method, which sets the last-modified time of a remote file. The first argument is an RFC 822 date-time string and the second is the remote filename.

Background: An upload normally leaves the remote file stamped with the time it arrived, which loses the original modification time — a problem for backups, mirrors, and timestamp-based sync. This method restores it, and Chilkat converts the supplied time to UTC before sending a server-supported command (typically MFMT). Whether it is honored depends on the server implementing such a command and granting permission.

Chilkat Java Downloads

Java
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.SetRemoteFileDateTimeStr method, which sets the last-modified time of a
    //  remote file.  The 1st argument is an RFC 822 date-time string and the 2nd is the remote
    //  filename.

    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");

    success = ftp.Connect();
    if (success == false) {
        System.out.println(ftp.lastErrorText());
        return;
        }

    //  Chilkat converts the date to UTC and sends a server-supported timestamp-setting command.
    success = ftp.SetRemoteFileDateTimeStr("Fri, 10 Jul 2026 20:15:30 -0600","public_html/report.pdf");
    if (success == false) {
        System.out.println(ftp.lastErrorText());
        return;
        }

    System.out.println("Remote file timestamp set.");

    success = ftp.Disconnect();
    if (success == false) {
        System.out.println(ftp.lastErrorText());
        return;
        }
  }
}