Read latest file name with a date and time and then download from FTP

Hi All,

Please help.

I have requirement to read the file / folder based on the latest date and download the file and folder.

There will be files and folders in the location like

20140630-144422
20140630-144422.csv
20140707-182653
20140707-182653.csv
20140710-183153
20140710-183153.csv
20140711-184040
20140711-184040.csv
20140715-185910
20140715-185910.csv
20140717-085017
20140717-085017.csv
20140719-121256
20140719-121256.csv

In the file list first number series before "-" is date and second number series is time.

I want to read latest file name with a date and time and then download it.

Thanks & regards
Praveen

Not sure I understand your problem. Are respective file and folder named identically (except for the .csv extension)? Use ls | tail -2 or ls | sort -r | head -2 .

1 Like

Hi Rudic,

Thanks for the reply. Respective file and folder names are always with date-time> So it will be always different.

Please advice.

Regards
Praveen

If they are always different, why are the all the same in your example??? Why do you even have directories if all of your directories and *.csv files are all in a single directory?

Is "the location" on your system? Or, is it on a remote system?

Read the filenames from what?

Download it from where? Download it to where?

1 Like

Hi Don Cragun,

Thanks for your reply.

I am repasting the filenames

20140630-144422
20140630-144422.csv
20140707-182653
20140707-182653.csv
  1. 20140630-144422 is a directory named after 30th June 2014 with a time at the end. Subsequently we have a input feed file as "20140630-144422.csv" for the same date.
  2. Similarly 20140707-182653 is a directory named after 7th July 2014 with a time at the end. Subsequently we have a input feed file as "20140707-182653.csv" for the same date.

File and folder names are different because each one is identified by date and time. Each ".csv" file is accompanied with a directory with a same name.
Directory contains all images and the CSV file contains data which needs to be associated with the images. The provider puts data and the images daily.
Only the file with current date (time need not be checked) has to be pulled from the FTP location for processing.

I want to download the images from the latest directory and save it in the server under one path for example /websites/www.abc.com/images. And CSV has to be downloaded under another
path like "/root/dataprocess/abc".

Please help.

Regards
Praveen

Please help. I am stuck :frowning:

This is totally untested, but if you want today's files, I think you want something like:

latest_dir=$(date "+%Y%M%D-*[0-9]")
host="put remote hostname here"
ftp <<<-EOF
	ftp $host
	cd /websites/www.abc.com/images
	lcd /root/dataprocess/abc
	mget "$latest_dir.csv" "$latest_dir/*"
EOF
1 Like

Thank you Mr.Don Cragun.