I've build an FTP class in PHP with a function to download files from the FTP server.
This is the function so far
public function downloadData($serverFile, $localPath)
{
$fileName = basename($serverFile);
$file = $localPath.$fileName;
$download = false;
if(!file_exists($file))
{
// try to download $server_file and save to $local_file
if(ftp_get($this->connection_id, $file, $serverFile, FTP_BINARY)) {
$download = true;
}
}
return $download;
}
Basically it works fine, but when saving the data the "last change date" of the file is set to the current date/time. I somehow want to prevent this, because the original date is important for my needs.
Is there a way to keep the original modified date of the file?
It sounds like you believe there's something overwriting the timestamp. There's not. The timestamp is simply not transferred at all during an FTP download. So the local file has last modification time matching the transfer time (= the last time the local file was modified).
But you can of course explicitly set the timestamp after the download finishes.
ftp_mdtm
to retrieve the timestamp of source file on FTP server.touch
to set the timestamp of target local file.touch($file, ftp_mdtm($this->connection_id, $serverFile));
You cannot stop the system from updating the modified date when modifying a file. However, it depends drastically on why you need the creation date?
Unfortunately if you are running on Linux/Unix you cannot access the creation date information as only the last modified date is stored. However for Windows you can use filectime and it will return the creation time