0

When I use WinSCP to access my SFTP server, it shows me the last modified (changed) date including seconds. If I use sftp on Linux and run ls -l, it only shows the hours and minutes, but no seconds. How can I also show the seconds using sftp, like WinSCP does it?

I already checked the sftp man page and the ls options there, but could not find a matching option.

3 Answers 3

2

You can always switch to a different SFTP client that supports it.

For instance, with lftp (which supports a large number of file transfer protocols including SFTP), you can use its cls command which does the formatting client-side and has a --time-style option à la GNU ls:

lftp chazelas@localhost:/usr> cls --time-style=+%FT%T%z -l drwxr-xr-x 1 root root 60478 2024-12-17T06:12:02+0000 bin/ drwxr-xr-x 1 root root 0 2024-11-03T13:06:44+0000 games/ drwxr-xr-x 1 root root 4166 2024-12-15T13:01:36+0000 include/ drwxr-xr-x 1 root root 2636 2024-12-11T19:47:15+0000 lib/ drwxr-xr-x 1 root root 1626 2024-12-06T07:54:35+0000 lib32/ drwxr-xr-x 1 root root 40 2024-12-06T07:54:40+0000 lib64/ drwxr-xr-x 1 root root 6312 2024-12-17T06:12:15+0000 libexec/ drwxr-xr-x 1 root root 1728 2024-12-06T07:54:38+0000 libx32/ drwxr-xr-x 1 root root 72 2021-06-27T07:13:26+0100 local/ drwxr-xr-x 1 root root 12014 2024-12-17T06:12:15+0000 sbin/ drwxr-xr-x 1 root root 6646 2024-12-13T12:56:11+0000 share/ drwxr-xr-x 1 root root 0 2024-11-03T13:14:31+0000 src/ 
lftp chazelas@localhost:/usr> cls --time-style=full-iso -l drwxr-xr-x 1 root root 60478 2024-12-17 06:12:02 bin/ drwxr-xr-x 1 root root 0 2024-11-03 13:06:44 games/ drwxr-xr-x 1 root root 4166 2024-12-15 13:01:36 include/ drwxr-xr-x 1 root root 2636 2024-12-11 19:47:15 lib/ drwxr-xr-x 1 root root 1626 2024-12-06 07:54:35 lib32/ drwxr-xr-x 1 root root 40 2024-12-06 07:54:40 lib64/ drwxr-xr-x 1 root root 6312 2024-12-17 06:12:15 libexec/ drwxr-xr-x 1 root root 1728 2024-12-06 07:54:38 libx32/ drwxr-xr-x 1 root root 72 2021-06-27 07:13:26 local/ drwxr-xr-x 1 root root 12014 2024-12-17 06:12:15 sbin/ drwxr-xr-x 1 root root 6646 2024-12-13 12:56:11 share/ drwxr-xr-x 1 root root 0 2024-11-03 13:14:31 src/ 

Like the sftp that comes with openssh, it looks like it doesn't support displaying the access time, change time, birth time or subsecond part of the modification time even though, looking at the code it does have support for retrieving those over the protocol.

yafc (FTP and SFTP client) has a filetime command which gives the last modification time with second precision:

yafc chazelas@localhost:/usr> filetime src src: Sun Nov 3 13:14:31 2024 

Or you can use the Net::SFTP::Foreign perl module:

$ perl -MPOSIX -MNet::SFTP::Foreign -le ' $s = Net::SFTP::Foreign->new("localhost"); print strftime("%FT%T%z ", localtime $_->{a}->mtime) . $_->{filename} for @{$s->ls("/usr")}' 2021-06-27T07:13:26+0100 . 2024-12-03T08:22:33+0000 .. 2024-12-17T06:12:02+0000 bin 2024-12-17T06:12:15+0000 sbin 2024-12-11T19:47:15+0000 lib 2024-12-06T07:54:35+0000 lib32 2024-12-06T07:54:40+0000 lib64 2024-12-06T07:54:38+0000 libx32 2024-12-13T12:56:11+0000 share 2024-11-03T13:06:44+0000 games 2024-12-15T13:01:36+0000 include 2024-11-03T13:14:31+0000 src 2024-12-17T06:12:15+0000 libexec 2021-06-27T07:13:26+0100 local 

(only mtime and atime (not Btime, ctime) and no subsecond precision)

Another option is to use sshfs (which uses the SFTP protocol underneath) to mount the remote FS locally, then you can use local commands to display those timestamps. However, testing here on Debian trixie it doesn't look like subsecond precision nor birth time are supported:

$ sshfs localhost:/usr mnt $ ls --full-time mnt total 116 drwxr-xr-x 1 root root 60478 2024-12-17 06:12:02.000000000 +0000 bin/ drwxr-xr-x 1 root root 0 2024-11-03 13:06:44.000000000 +0000 games/ drwxr-xr-x 1 root root 4166 2024-12-15 13:01:36.000000000 +0000 include/ drwxr-xr-x 1 root root 2636 2024-12-11 19:47:15.000000000 +0000 lib/ drwxr-xr-x 1 root root 1626 2024-12-06 07:54:35.000000000 +0000 lib32/ drwxr-xr-x 1 root root 40 2024-12-06 07:54:40.000000000 +0000 lib64/ drwxr-xr-x 1 root root 6312 2024-12-17 06:12:15.000000000 +0000 libexec/ drwxr-xr-x 1 root root 1728 2024-12-06 07:54:38.000000000 +0000 libx32/ drwxr-xr-x 1 root root 72 2021-06-27 07:13:26.000000000 +0100 local/ drwxr-xr-x 1 root root 12014 2024-12-17 06:12:15.000000000 +0000 sbin/ drwxr-xr-x 1 root root 6646 2024-12-13 12:56:11.000000000 +0000 share/ drwxr-xr-x 1 root root 0 2024-11-03 13:14:31.000000000 +0000 src/ 
$ ls --time=birth -l mnt total 116 drwxr-xr-x 1 root root 60478 ? bin/ drwxr-xr-x 1 root root 0 ? games/ drwxr-xr-x 1 root root 4166 ? include/ drwxr-xr-x 1 root root 2636 ? lib/ drwxr-xr-x 1 root root 1626 ? lib32/ drwxr-xr-x 1 root root 40 ? lib64/ drwxr-xr-x 1 root root 6312 ? libexec/ drwxr-xr-x 1 root root 1728 ? libx32/ drwxr-xr-x 1 root root 72 ? local/ drwxr-xr-x 1 root root 12014 ? sbin/ drwxr-xr-x 1 root root 6646 ? share/ drwxr-xr-x 1 root root 0 ? src/ 

Or Gnome I/O (as you'd use in nautilus, Gnome's default file manager for instance) and its gio CLI interface:

$ gio mount sftp://localhost/usr $ gio list -a time sftp://localhost/usr bin 60486 (directory) time::modified=1734422749 time::access=1734422773 sbin 12014 (directory) time::modified=1734415935 time::access=1734415955 lib 2636 (directory) time::modified=1733946435 time::access=1734415801 lib32 1626 (directory) time::modified=1733471675 time::access=1734415801 lib64 40 (directory) time::modified=1733471680 time::access=1734036576 libx32 1728 (directory) time::modified=1733471678 time::access=1734415801 share 6646 (directory) time::modified=1734094571 time::access=1734277015 games 0 (directory) time::modified=1730639204 time::access=1732375138 include 4166 (directory) time::modified=1734267696 time::access=1734330298 src 0 (directory) time::modified=1730639671 time::access=1732479037 libexec 6312 (directory) time::modified=1734415935 time::access=1734415955 local 72 (directory) time::modified=1624774406 time::access=1732384794 
$ gio info sftp://localhost/usr/src display name: src edit name: src name: src type: directory size: 0 uri: sftp://localhost/usr/src local path: /run/user/1000/gvfs/sftp:host=localhost/usr/src unix mount: gvfsd-fuse /run/user/1000/gvfs fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 attributes: standard::type: 2 standard::is-symlink: FALSE standard::name: src standard::display-name: src standard::edit-name: src standard::icon: inode-directory, folder, inode-directory-symbolic, folder-symbolic standard::content-type: inode/directory standard::fast-content-type: inode/directory standard::size: 0 standard::symbolic-icon: inode-directory-symbolic, folder-symbolic, inode-directory, folder etag::value: 1730639671 id::filesystem: sftp:host=localhost access::can-read: TRUE access::can-execute: TRUE access::can-trash: FALSE time::modified: 1730639671 time::access: 1732479037 unix::mode: 16877 unix::uid: 0 unix::gid: 0 
$ ls -l --full-time /run/user/1000/gvfs/sftp:host=localhost/usr total 97 drwxr-xr-x 1 chazelas chazelas 60486 2024-12-17 08:05:49.000000000 +0000 bin/ drwxr-xr-x 1 chazelas chazelas 0 2024-11-03 13:06:44.000000000 +0000 games/ drwxr-xr-x 1 chazelas chazelas 4166 2024-12-15 13:01:36.000000000 +0000 include/ drwxr-xr-x 1 chazelas chazelas 2636 2024-12-11 19:47:15.000000000 +0000 lib/ drwxr-xr-x 1 chazelas chazelas 1626 2024-12-06 07:54:35.000000000 +0000 lib32/ drwxr-xr-x 1 chazelas chazelas 40 2024-12-06 07:54:40.000000000 +0000 lib64/ drwxr-xr-x 1 chazelas chazelas 6312 2024-12-17 06:12:15.000000000 +0000 libexec/ drwxr-xr-x 1 chazelas chazelas 1728 2024-12-06 07:54:38.000000000 +0000 libx32/ drwxr-xr-x 1 chazelas chazelas 72 2021-06-27 07:13:26.000000000 +0100 local/ drwxr-xr-x 1 chazelas chazelas 12014 2024-12-17 06:12:15.000000000 +0000 sbin/ drwxr-xr-x 1 chazelas chazelas 6646 2024-12-13 12:56:11.000000000 +0000 share/ drwxr-xr-x 1 chazelas chazelas 0 2024-11-03 13:14:31.000000000 +0000 src/ 

The KIO KDE equivalent:

$ kioclient stat sftp://localhost/usr/src NAME src SIZE 0 FILE_TYPE 0040000 USER 0 GROUP 0 ACCESS 0755 MODIFICATION_TIME Sun Nov 3 13:14:31 2024 ACCESS_TIME Sun Nov 24 20:10:37 2024 
1
  • nice, today I learned there's a free-standing gio utility. Handy! Commented Dec 17, 2024 at 12:10
1

It seems the sftp client doesn't do that.

So, I'm afraid your only option is to either use regular ssh server_name ls -l /path/to/file to read these properties, or use the (maybe elegant?) ability of Linux to have userland file systems, and use sshfs server:/path/to localdirectory/ && ls -l --time-style=long-iso localdirectory.

2
  • However he wants to see seconds, and mere ls -l will not show show them... Commented Dec 16, 2024 at 20:14
  • @Arfrever well, true. Add --time-style=long-iso (or follow your example)! Commented Dec 16, 2024 at 20:20
1

According to Man page of sftp, it is not possible to display the full time of file.

# man sftp ls [-1afhlnrSt] [path] Display a remote directory listing of either path or the current directory if path is not specified. path may contain glob(7) characters and may match multiple files. The following flags are recognized and alter the behaviour of ls accordingly: -1 Produce single columnar output. -a List files beginning with a dot (‘.’). -f Do not sort the listing. The default sort order is lexicographical. -h When used with a long format option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte, Petabyte, and Exabyte in order to reduce the number of digits to four or fewer using powers of 2 for sizes (K=1024, M=1048576, etc.). -l Display additional details including permissions and ownership information. -n Produce a long listing with user and group information presented numerically. -r Reverse the sort order of the listing. -S Sort the listing by file size. -t Sort the listing by last modification time. 

https://man.openbsd.org/sftp#ls

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.