0

Objective:

Connect to sftp server with very simple script using -b option, cd to directory and get file with the latest modified time or created time.

I can connect and download *.csv but that may download a dozen; I can provide part of the file name but that changes monthly, so I think the best solution is mtime.

Thanks!

1 Answers1

2

If you take a look to sftp manual (sftp(1)) you can see there is a way to perform a ls sorting by mtime (ls -t). So you can run sftp twice:

First time you perform a ls -lt (or ls -lrt to reverse order) redirect the output to a file and just read the last line of listing, so you have the filename, and on the second round you can specify the file to download.

alphamikevictor
  • 1,062
  • 6
  • 19