Timestamp Issue
TLDR - Quick Summary
Problem: In SFTP Gateway 3.2.1 and earlier, files uploaded to S3 outside SFTP Gateway show the current date and time in SFTP clients
Cause: SFTP Gateway reads timestamps from its own S3 metadata, which those files don't have
Fix: Upgrade to SFTP Gateway 3.3.0 or later. Files without SFTP Gateway metadata then show the S3 object's own Last Modified date
Related: Extra S3 object versions or
ObjectCreated:Copyevents from a client's "preserve timestamps" option are a separate behavior, configurable from 3.9.0
Overview
In SFTP Gateway 3.2.1 and earlier, SFTP clients show the current date and time for files that were uploaded to S3 by other means, such as the S3 console or the AWS CLI, or that were in the bucket before SFTP Gateway was installed. These timestamps change to the current time every time the listing refreshes. Files uploaded through SFTP Gateway show their correct timestamps.
SFTP Gateway 3.3.0 fixed this. If you see this behavior, check your version and upgrade.
How SFTP Gateway determines file timestamps
SFTP Gateway stores a file's modified, created and accessed times in S3 user metadata (x-amz-meta-mtime, x-amz-meta-ctime and x-amz-meta-atime) when it uploads the file, and when an SFTP client sets the file's timestamp.
When it lists a file, SFTP Gateway uses:
- Its own timestamp metadata, when the object has it
- Otherwise, the S3 object's Last Modified date
For example, a file uploaded with aws s3 cp shows the time of that upload, the same date the S3 console shows as Last modified.
Folders work the same way:
- A folder object, for example one created with Create folder in the S3 console, shows that object's Last Modified date
- A folder that exists only as part of object keys, with no folder object, shows the bucket's creation date. Reading it requires the
s3:ListAllMyBucketspermission, which the IAM policies in Instance Identity include. Without that permission, these folders show the current date and time.
Timestamps from "preserve timestamps" uploads
The behavior above only affects how timestamps are displayed. A separate behavior applies when an SFTP client has a "preserve timestamps" option enabled, for example FileZilla's Preserve timestamps of transferred files.
With that option, the client asks SFTP Gateway to set the file's original timestamp. When SFTP Gateway applies the timestamp to an object that is already in S3, it uses an S3 server-side copy of the object. In a bucket with versioning enabled, that copy adds an object version, and it emits an additional ObjectCreated:Copy event, which can trigger event-driven workflows twice.
From SFTP Gateway 3.9.0, you can stop SFTP Gateway from writing client-set timestamps to S3:
features.file-system.aws-s3.ignore-client-set-times=true
With this setting, SFTP Gateway still accepts the client's request but writes nothing to S3. The object keeps its upload time, and each upload produces one creation event. See Application Properties for how to change settings.