I have a 3rd-party SFTP server on which I want to check some file timestamps.

However, I do get different results for the same file if I use ls -l vs. ls -lh:

sftp> ls -l
-rwxrwxrwx 1 0        0               1963 Nov 15 08:49 foo.txt

sftp> ls -lh
-rwxrwxrwx    0 0        0            1.9K Nov 15 07:49 foo.txt

sftp> ls -l foo.txt
-rwxrwxrwx    0 0        0            1963 Nov 15 07:49 foo.txt

sftp> ls -lh foo.txt
-rwxrwxrwx    0 0        0            1.9K Nov 15 07:49 foo.txt

As you can see, the timestamp in ls -l is 08:49 whereas the other commands have 07:49. The server is in Germany which currently is 1h later than UTC, so my guess is that 07:49 is UTC whereas 08:49 is Berlin time.

However, my machine is on UTC:

$ cat /etc/timezone 

My understanding is that, according to the SFTP standard, all timestamps should be in UTC. However I'm not sure whether that understanding is correct (given that there are so many different versions of the standard). I also don't know whether the sftp tool somehow postprocesses the timestamps (man sftp doesn't mention timezones or timestamps at all).

What could be the reason for the difference?

1 Answer 1


When listing a directory using SFTP protocol, the server provides both structured metadata of files (name, timestamp, size, etc) and textual listing of files.

The OpenSSH sftp with -l switch prints the textual representation (as formatted by the server). In this case the times are printed according to the server's timezone (at least with the OpenSSH server).

But with -h switch, the client has to format the listing from the structured metadata on its own (due to the forced custom formatting of the size), including the timestamp. That's where the difference comes from. The OpenSSH sftp client formats the timestamps according to its timezone.

When "listing" specific files, the OpenSSH sftp probably uses the SFTP "stat" request (not a directory listing, as in the SFTP protocol, the directory listing request does not support filtering to a specific file or a mask). The response to the SFTP "stat" request contains only the structured metadata, not the textual listing. So in this case, the client always have to format the listing locally. So that's why the timestamp matches the timestamp of -h.

Regarding the BugZilla entry you have found: I understand that from user perspective you might see it as a bug. But there's not much the OpenSSH sftp client can do about it, if it wants to offer formatting capabilities like -h. All it could do is to always format the listing locally to maintain consistency (that's what my WinSCP's ls command does for example). But then it would give up on displaying potentially useful (platform specific/proprietary) information contained in the server-side listing.

  • To me that sounds like a bug and indeed there is already a ticket for it: bugzilla.mindrot.org/show_bug.cgi?id=3021 Commented Nov 15, 2021 at 12:25
  • @MartinPrikryl: The very least that I would expect is that something like this is mentioned in the man page. Personally, I would expect the "standard" commands to behave intuitively, especially I wouldn't expect ls -l FILENAME and ls- l to behave differently. One could always offer non-standard, server-dependent behavior using a flag or a separate command. But I guess that discussion it better suited for the ticket I've linked to. Commented Nov 16, 2021 at 9:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .