soField
soField

Reputation: 2686

ftp getting last modified file by date

i am connecting remote server via ftp and i am sending ls -t command but it's outputting files sorted by name

how can i get last modified file via ftp ?

Note: i am connecting windows ftp server from linux machine

Upvotes: 6

Views: 36024

Answers (4)

Mrk
Mrk

Reputation: 555

try this one, it worked for me.

ls -t1 | head -1

Upvotes: 2

David W.
David W.

Reputation: 107040

In most Unix/Linux based ftp servers, the ls command is linked to the actual ls command. This is why all the other answers are saying to use ls -t with maybe a few more parameters thrown in.

However, since you're using a Windows machine as your server, it's much harder to say how exactly the command will work. I don't believe Windows comes with a default FTP server service. I know many sites use third party FTP services on their Windows machines. It's going to depend on the software your Windows machine is using, and how it's been setup:

Try something like this:

ftp> dir /O:D

or

ftp> ls /O:D

These use the Windows parameters for the built in dir command.

Upvotes: 2

ghostdog74
ghostdog74

Reputation: 342363

ftp -n server <<EOF|awk 'END{for(i=9;i<=NF;i++)printf "%s ",$i}'
user username password
ls -ltr
EOF

Upvotes: 2

JoseK
JoseK

Reputation: 31371

ls -t will give you the last modified file on top

You can confirm this by viewing with full timestamps

ls -lt

Upvotes: 5

Related Questions