Core\FileTransfer\Entry::modifiedAt
$entry->modifiedAt(): ?Core\Time\InstantReturns the time a file or folder on the server was last changed.
$entry->modifiedAt() returns a Core\Time\Instant, or null when the server does not send the time. Most servers send it in the listing, so reading it costs no extra request. Check for null before you compare the time. $entry->modifiedAt()?->toIso() calls toIso only when the time is not null. Otherwise the result is null.
An SFTP server sends the time in whole seconds. An FTP server sends whole seconds or milliseconds. setModifiedAt on the connection changes the time of a file.
The entry keeps the time from the moment list, walk or metadata read it. When the file changes after that, call metadata again for the new time.
The examples below set and read the time of a file, check for a missing time, and find the files that changed since a job's last run.
Return value
Returns ?Core\Time\Instant. The time, or null when the server does not send it.
Changelog
| Version | Change |
|---|---|
0.0.6 | list and walk return one Core\FileTransfer\Entry for each file or folder, and it has the same methods as Core\IO\Entry. Its size, modifiedAt and permissions methods return null when the server does not send the value. Every string it returns is tainted: the server chose it, so the methods of the connection do not accept it until your program checks it. |
Examples
The examples below run with this configuration file.
# The `partner` block reads the folder `partner` beside this file. It needs no server.[file_transfer.partner]directory = "partner"
# The program may open the `partner` block, and read and change the files in its folder.[capabilities.file_transfer]connect = ["partner"]
[capabilities.fs]read = ["partner"]write = ["partner"]Set and read the time
<?nvs// Shows how to set the time of a file with `setModifiedAt`, then read it with `modifiedAt()`.
var $partner = Core\FileTransfer::open('partner');$partner->write('report.csv', "month,total\n2026-03,1410\n" as bytes);$partner->setModifiedAt('report.csv', Core\Time\Instant::fromIso('2026-03-01T12:00:00Z'));
// `modifiedAt()` returns a `Core\Time\Instant`, or `null` when the server does not send it.// This prints "2026-03-01T12:00:00Z".echo $partner->metadata('report.csv')->modifiedAt()?->toIso() ?? 'no time', "\n";
$partner->remove('report.csv');2026-03-01T12:00:00ZWhen the time is missing
<?nvs// Shows how a program checks for `null` before it uses the time a file or folder was last changed.
var $partner = Core\FileTransfer::open('partner');
// `modifiedAt()` returns `null` when the file server sends no time. This server sends a time// for each file and folder in `reports`, so this prints "has a time" three times.foreach ($partner->list('reports') as Core\FileTransfer\Entry $entry) { Core\Time\Instant|null $changed = $entry->modifiedAt(); echo $entry->name(), ': ', $changed == null ? 'no time' : 'has a time', "\n";}2026-01.csv: has a time2026-02.csv: has a timearchive: has a timeDownload only changed files
<?nvs// Shows how a sync job finds the files that changed on the server since its last run.
var $partner = Core\FileTransfer::open('partner');
// The job last ran on 1 March. The program writes three files and sets a different time on each.$partner->makeDirectory('outbox');$partner->write('outbox/stock.csv', "sku,count\n" as bytes);$partner->setModifiedAt('outbox/stock.csv', Core\Time\Instant::fromIso('2026-02-10T08:00:00Z'));$partner->write('outbox/prices.csv', "sku,price\n" as bytes);$partner->setModifiedAt('outbox/prices.csv', Core\Time\Instant::fromIso('2026-03-05T08:00:00Z'));$partner->write('outbox/orders.csv', "id,total\n" as bytes);$partner->setModifiedAt('outbox/orders.csv', Core\Time\Instant::fromIso('2026-03-20T08:00:00Z'));Core\Time\Instant $lastRun = Core\Time\Instant::fromIso('2026-03-01T00:00:00Z');
// A file with no time is also downloaded, because it may have changed. Here each file has a time.// "stock.csv" changed before the last run. This prints "download orders.csv" and "download prices.csv".foreach ($partner->list('outbox') as Core\FileTransfer\Entry $entry) { Core\Time\Instant|null $changed = $entry->modifiedAt(); if ($changed == null || $changed->compareTo($lastRun) > 0) { echo 'download ', $entry->name(), "\n"; }}
$partner->remove('outbox/stock.csv');$partner->remove('outbox/prices.csv');$partner->remove('outbox/orders.csv');$partner->removeDirectory('outbox');download orders.csvdownload prices.csv