Hello Experts...
dir
of FTP
will list all the files in the directory. Is there any command or option of dir
that will give me the most recent file only?
Since I couldn't find any such thing, I thought of creating a log file (of FTP results) and work on this log file to determine the most recent file name. Then go back to FTP and get this file. Does it sounds good?
regards,
juzz4fun
When you post it helps if we know the OS you use and the shell (ksh, bash, etc).
The reason is: in this case there is a specific answer for Linux with GNU date.
My apologies...
It is SunOS
...and using ksh
...
Sorry there is no GNU
---------- Post updated 06-19-13 at 10:32 AM ---------- Previous update was 06-18-13 at 07:17 PM ----------
I assume there is no such FTP command that gives me only the most recent file..
To get the work done, I have created a log file which contains the dir's
output as shown:
Connected to XXX.XXX.XXX.XXX.
220 EFT Server 6.4.10 Build XX.XX.XXXX.X
331 Password required for XXXXX.
230 Login OK. Proceed.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 250 Folder changed to "/XX/XXXXXXX/XXXX/XXXX".
ftp> 200 Command okay.
150 Opening ASCII mode data connection for file list.
-rw-rw-rw- 1 user group 8031232 Apr 13 2010 A100323.xls
-rw-rw-rw- 1 user group 9041408 Jun 30 2010 A100628.xls
-rw-rw-rw- 1 user group 4178690 Sep 30 2012 A100929.xlsx
-rw-rw-rw- 1 user group 1800395 Dec 30 2010 A101230.xlsx
-rw-rw-rw- 1 user group 1526971 Mar 31 2011 A110330.xlsx
-rw-rw-rw- 1 user group 1789926 Sep 19 2011 A110630.xlsx
-rw-rw-rw- 1 user group 2068925 Sep 13 2011 A110919.xlsx
-rw-rw-rw- 1 user group 1945225 Sep 30 2011 A110929.xlsx
-rw-rw-rw- 1 user group 1213118 Dec 30 2012 A111230.xlsx
-rw-rw-rw- 1 user group 3449169 Feb 13 2012 A120213.xlsx
-rw-rw-rw- 1 user group 8917313 Mar 30 2012 A120330.xlsx
-rw-rw-rw- 1 user group 1323563 Jun 28 2012 A120626.xlsx
-rw-rw-rw- 1 user group 1517358 Jan 27 2012 A120927.xlsx
-rw-rw-rw- 1 user group 1926533 Dec 21 2012 A121231.xlsx
226 Transfer complete. 964 bytes transferred. 964 bps.
964 bytes received in 0.00022 seconds (4316.40 Kbytes/s)
ftp> 221 Service closing control connection.
Then I replaced Jan
with 1
, Feb
with 2
and so on... this part of script I have written in scr
file and execute it like ./scr
. Output of scr
is piped to below commands to get the most recent file name...
scr
also contains grep '^-.*xlsx$'
to get only the required rows from log file...
./scr | sort -k8n -k6n -k7n | tail -1 | awk '{print $NF}'
.... which gives me output as A111230.xlsx
Is there any way I can achieve the same result in some shorter way?