Java Requires Chilkat v11.0.0+
Chilkat2 Java
FTP Set Remote File Date/Time Equal to Local File's Last-Modified Date/Time
See more FTP Examples
Demonstrates how to set a remote file's date/time to be equal to a local file's date/time.Important: Not all FTP servers support the ability to set a file's date/time.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.DateTime;
import com.chilkatsoft.chilkat2.FileAccess;
import com.chilkatsoft.chilkat2.Ftp2;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.
Ftp2 ftp = new Ftp2();
ftp.setHostname("www.authtls-ftps-server.com");
ftp.setUsername("FTP_LOGIN");
ftp.setPassword("FTP_PASSWORD");
ftp.setAuthTls(true);
ftp.setPort(21);
// Connect to the FTP server using explicit TLS (AUTH TLS).
try {
ftp.connectOnly();
// Authenticate.
ftp.loginAfterConnectOnly();
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// We're going to get the last-mod date/time for the local file
// "qa_data/hamlet.xml", and then set the remote "hamlet.xml" to this date/time.
FileAccess fac = new FileAccess();
DateTime dt = new DateTime();
String lastModTimestamp = fac.getFileTimeStr("qa_data/hamlet.xml", 0);
dt.setFromTimestamp(lastModTimestamp);
try {
ftp.setRemoteFileDt(dt, "hamlet.xml");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
dt.close();
return;
}
ftp.disconnect();
System.out.println("Success.");
}
}