Getting the timestamp of a file from a SFTP server using ls
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:
- mounting remote directory as disk "New-PSDrive -name $diskLiteral -psprovider FileSystem -Root $outsightFolder -Credential $cred"
- geting sorted list of files in directory "Get-ChildItem ($diskLiteral + $subfolder) -Force | Where-Object $_.CreationTime -ge $targetDate"
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).