php - phpseclib enableDatePreservation not preserving date

Maybe somebody out here may have encountered this issue before. I am using phpseclib version 3.
My code is basically uploading a file via SFTP to another server. The connection part is good, and the upload also pushes through.
However, I need to maintain the date modified for the uploaded file. Currently the files uploaded get the time they are uploaded as the date modified.
require_once __DIR__ . '/vendor/autoload.php';
use phpseclib3\Net\SFTP;
$server = "xxx.com";
$username = "xxxx";
$password = "xxxxxx";
$sftp = new SFTP($server);
$sftp->enableDatePreservation();
if($sftp->login($username, $password)){
$test1 = $sftp->put("public_html/Content/". basename($filename), $filename, SFTP::SOURCE_LOCAL_FILE);
if ($test1) { echo "upload ok"; } else { echo "not ok"; }
Note that this is just rough code, just proof of concept at this point. Just trying to get the file modified date/time to transfer over. I also tried adding the enableDatePreservation AFTER the $sftp-put. I also tried uploading to different servers, just in case it is a user permission problem. same result.
Hopefully someone out there has some insights! Thanks a lot!
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: using $this when not in object context laravel
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.