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 Answer 1

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.

3
  • Make sense but how do I re-direct output? ls -lrt > alphamikevictor Can't ls: "/usr/home/aaa/u/zzz/>" not found May 14, 2015 at 5:26
  • When you launch the SFTP sftp -b listfiles.sftp > files_listed.log (being listfiles.sftp your batch file) May 14, 2015 at 8:48
  • Just linking to a similiar question I didn't find last night: serverfault.com/questions/507394/… May 15, 2015 at 5:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .