Visit Our UNIX and Linux User Community

FTP command to get most recent file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP command to get most recent file
# 1  
Old 06-18-2013
FTP command to get most recent file

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?

# 2  
Old 06-18-2013
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.
# 3  
Old 06-19-2013
My apologies...
It is SunOS...and using ksh...
Sorry there is no GNU Smilie

---------- 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?

Previous Thread | Next Thread
Test Your Knowledge in Computers #273
Difficulty: Easy
In December 1939, Turing solved the essential part of the naval indicator system, which was easier and less complex than the indicator systems used by the other services.
True or False?

10 More Discussions You Might Find Interesting

1. Solaris

Recent file available

Dear, Require a script to check : If the file under /opt/OV/log directory has recent 5 hours(or user defined value) file generated or not If generated then cmd to call : opcmsg a=a o=o msg_grp=OpC msg_text="Log file didn't generated on $time" s=critical (1 Reply)
Discussion started by: mjoshi87
1 Replies

2. UNIX for Dummies Questions & Answers

command to find most recent file

Hi, Here is my problem: I try to write a script to find data in a file named "data" for exemple. Let's say I am in the directory /x/y/z, there are several sub-directories in the "z" directory (each sub-directory has a file "data") and I am searching for the word "help". So I use this... (9 Replies)
Discussion started by: StephB
9 Replies

3. UNIX for Advanced & Expert Users

vi recent command history

How do you get your recent vi command history to show up? I keep randomly getting like my previous 5 commands and can't figure out how I'm doing it. I think it has something to do with the shift key and another button. (6 Replies)
Discussion started by: cokedude
6 Replies

4. AIX

script to ftp recent changed files

I am trying to write a script to ftp all files/directories changed in a 24hour period to another AIX server. I have wrote a script to generate a list of all files changed within a 24 hour period but dont know how to then ftp these to another server. How do incorporate ftp into this script? ... (2 Replies)
Discussion started by: RApds
2 Replies

5. Shell Programming and Scripting

Getting the most recent file

Hi people, Please some help over here. I have logs in a directory, in which I need to get the most recent file in order to put it within other command. The format of the files are loadfiles20090308094339_41 loadfiles20090308094418_42 loadfiles20090308095457_43... (4 Replies)
Discussion started by: cgkmal
4 Replies

6. Linux

tail most recent file command

I have only been working with Linux for a few years now so bear with my noob question. I was wondering if there is a way to tail the most recent file that has a file name like 'scrubsncoa%'. There will be at least 2 files in the directory that start with 'scrubsncoa' and a few other different... (2 Replies)
Discussion started by: RyanD
2 Replies

7. Shell Programming and Scripting

Get Files from ftp which are uploaded recent week

Hi All, Here is a brief scenario for my requirement .. There is a directory in FTP Server, where would files be uploaded on weekly basic. I need to get those files which are uploaded during this week and not the files which are uploaded the previous week and download them to locale... (1 Reply)
Discussion started by: narramadan
1 Replies

8. Shell Programming and Scripting

getting the most recent file

Hi, I have files coming in every day with that days timestamp like: nameyyyymmddhhmmss.ext. I need the most recent one and so i am using cat `ls -t name*|head -1 ` > temp i am sorting the files in the decending order and am copying the most recent one into a temp file. It works at times... (3 Replies)
Discussion started by: anujairaj
3 Replies

9. AIX

Changing name of most recent file

I need to change the name of a file within a script. For example I have two files. The first named scrnslc_0001 and the second scrnslc_0002. I want to change the name of the second to scrnslc_out. The appended number will change, and I won't know the file name in advance. If there were only one... (1 Reply)
Discussion started by: warpmail
1 Replies

10. Shell Programming and Scripting

Most Recent File script

OK, I know next to nothing about scripting in unix, and at the moment I don't have access to a unix environment... We have an application that generates a text report file which is later printed. The format is this: bbtptcYYMMDDSSCC.txt (year/month/day/second/check digit) I want a... (1 Reply)
Discussion started by: josborn777
1 Replies

Featured Tech Videos