I'm currently writing a Powershell script which retrieves the timestamps of all files in a directory on a SFTP server and writes it to a file. I am using the sftp
utility which comes with cygwin to connect to the server.
The issue that I am having is that the ls
command does not show the year in the timestamp. This is an example of the output:
sftp> ls -lt
-rw-r--r-- 1 9665 9665 358 Mar 13 10:05 file.txt
-rw-r--r-- 1 9665 9665 217 Mar 13 10:00 file2.txt
I don't seem to have access to any of the flags which force ls
to show the year for the regular ls
command. These are the options I have available to me via this:
ls [-1aflnrSt] [path] Display remote directory listing
I have tried using psftp
as well and it gives the same format without the year.
My question is how can I ensure that the year is shown in the date? This would be the ideal solution. But if it can't be shown, is it simply safe to assume that the file is from the current year, and that any files from previous years would specifically specify the year? Is this the default behavior of ls
over sftp?
Ways to do that: I. You can parse date in string and try to find 4 numbers in a row. Also add checking of containig "19","20" or $targetYear going firsts.
II. Also you may use "ls -l --full-time" command showing year.
III. And at last in my practice working with files in remote Linux servers I used:
unmounting directory "Remove-PSDrive -Name $diskLiteral -Force -PSProvider FileSystem".
On second step you can add any sorting as you want, select any information about files and Format-Table (if it nessesary table form of data representation).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With