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?

  • Could you possibly clarify the client software you are using? – Burgi Nov 14 '17 at 9:15
  • 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 Nov 14 '17 at 9:17
  • You should edit your question to include that information. Please see How to Ask and take our tour. – Burgi Nov 14 '17 at 9:19

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.