How to get latest modified file?

Advertisement

LeonPix
Joined:
Posts:
3

How to get latest modified file?

Hi,

How to get lastest modified timestamped file in remote folder using script?

Meaning, after "cd remote_folder", I wanna "get file", which this file has latest modification timestamp at remote directory.

Thank you!

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
27,253
Location:
Prague, Czechia

Re: How to get latest modified file?

I do not understand what you ask for. Please try again :-)
_________________
Martin Prikryl

Reply with quote

LeonPix
Joined:
Posts:
3

Re: How to get latest modified file?

Let's say after we connect to a remote sftp site. By doing "ll" we got this:

31/07/2006 20:16 2,417,200 file_a
31/07/2006 22:16 2,484,770 file_b
31/07/2006 24:16 2,484,770 file_c

Timestamp of file_c has the latest timestamp.

How can we write a script to download file_c which has the latest timestamp in this directory?

Do I make myself clear in this case? Thanks!

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,253
Location:
Prague, Czechia

Re: How to get latest modified file?

I do not see any nice solution. One of the ugly ways that come to my mind is:
# make copy of the latest file with unique extension,
# so that it can be grabbed by file mask
# (note that you can make the copy in /tmp if needed)
call cp `ls -t | head -1` `ls -t | head -1`.latest 
# download the copy, but strip the extension
get *.latest *.
# remove the copy
rm *.latest    

Reply with quote

sunn
Guest

I am trying to do the same thing but problem is I need to have during the week 1 file and oon the weekend I need 3 files.

I need to have them by timestamp so easier to get by date. What would the code look like.

Reply with quote

sunn
Joined:
Posts:
1

sunn wrote:

I am trying to do the same thing but problem is I need to have during the week 1 file and oon the weekend I need 3 files.

I need to have them by timestamp so easier to get by date. What would the code look like.

Also I am using
C:\Program Files\WinSCP\WinSCP.com Logininfo /script=C:\Downloads\myscript.txt

I would like to add more to the script or make a new script similar to what i am using ( basic get statement ). That file on the ftp are .gz and need to converted in excel or csv format.

Reply with quote

Advertisement

You can post new topics in this forum