Can't run ls -e via SFTP

1

1

I'm trying to execute the command ls -e using a SFTP connection, but -e option is not available.

I need to get a date/time from creation file, example "Aug 11 19:36:40 2017"

I've already used the ls -e using a SSH connection, but due some restrictions I can't use this connection.

ls -l is not a good solution, because files older than 1 year I won't get information about hours and seconds.

I'm using a shell script with sftp command to connect to remote server.

Can someone help me with this situation?

Rui Caeiro

Posted 2017-11-14T09:05:01.417

Reputation: 11

Could you possibly clarify the client software you are using? – Burgi – 2017-11-14T09:15:26.510

I'm not using any specific client. I'm just using shell script and using the sftp command to connect to remote servers. – Rui Caeiro – 2017-11-14T09:17:31.557

You should [edit] your question to include that information. Please see [ask] and take our [tour]. – Burgi – 2017-11-14T09:19:58.117

Answers

2

OpenSSH sftp client does not support printing a full timestamp.

If you want to get a full file timestamp from an SFTP/SSH server, you have these options:

  • Use a different SFTP client, like lftp (as the answer by @gogators shows).
  • Use an SFTP library in some scripting language, like Perl, Python, PHP, etc.
  • If you have an shell access, use it to execute ls --full-time command on the server (or equivalent, if the server is not *nix-based). I'm aware that you have tried this already.

Martin Prikryl

Posted 2017-11-14T09:05:01.417

Reputation: 13 764

2

You can use lftp's cls command over an sftp connection to format the timestamps locally. The cls command has a --time-style=STYLE option. The format for STYLE is the same as the date command. For example:

lftp sftp://user@sftp.server.org
lftp sftp.server.org:~> cls -l --time-style=%FT%T file.txt
-rw-r-----   1 user   group      2032 2014-10-12T10:07:58 file.txt

gogators

Posted 2017-11-14T09:05:01.417

Reputation: 1 183