PHP Requires Chilkat v11.0.0+
Chilkat2 PHP
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 PHP Downloads
<?php
use Chilkat2\DateTime;
use Chilkat2\FileAccess;
use Chilkat2\Ftp2;
// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.
$ftp = new Ftp2();
$ftp->Hostname = 'www.authtls-ftps-server.com';
$ftp->Username = 'FTP_LOGIN';
$ftp->Password = 'FTP_PASSWORD';
$ftp->AuthTls = true;
$ftp->Port = 21;
// Connect to the FTP server using explicit TLS (AUTH TLS).
try {
$ftp->ConnectOnly();
// Authenticate.
$ftp->LoginAfterConnectOnly();
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// 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.
$fac = new FileAccess();
$dt = new DateTime();
$lastModTimestamp = $fac->GetFileTimeStr('qa_data/hamlet.xml', 0);
$dt->SetFromTimestamp($lastModTimestamp);
try {
$ftp->SetRemoteFileDt($dt, 'hamlet.xml');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
$ftp->Disconnect();
echo "Success.\n";