Script to cd into newest (dated) FTP directory

I have written the following simple bash script. It logs onto an FTP site and then CDs into a directory that corresponds to the last business day. So for example the directory I would access today is 20060110 (2006 jan 10).

I am currently taking today's date and subtracting 1, putting this into a variable and then entering ftp mode, cd'ing to the directory (in the variable) and downloading the file (always same filename). This obviously does not work for weekends and holidays, as subtracing 1 on monday would give sunday. There are no directories created on weekends and holidays.

My two ideas to rectify this are 1) do something complex to figure out the last business day before entering ftp mode or 2) figure out how to CD into the newest directory, regardless of its name (the newest directory will always be the previous day).

Any ideas are appreciated here. Maybe there is a much easier way to do this that I am not considering?

Thanks in advance for any help, this is my first post.

Steve D.
Chicago, Illinois

mydate=$(date +%F | tr -d [:punct:])
let prevdate=$mydate-1
user='xxxxxxx'
pass='xxxxx'

ftp -n ftp.xxxxxxx.com << ENDEND
passive
user xxxxx xxxxx
hash
cd $prevdate
get POA_133_Position.csv
quit
ENDEND
echo "Done."
exit 0

you can use the datecalc function posted in the following link...

http://www.unix.com/showthread.php?p=16559\#post16559

if it is monday you can subtract -2 from current day so that you will get friday's date..

But for holidays, you can maintain a config file with holiday list, deduct -1 from current day and check whether this date is in config file, if it is there, then again deduct -1 from the previously arrived date ( current day - 1 ), again check in the config file... till it is not their in the config file. I don't think this will be too complex to do..

Suppose this was Feb 1. You get 20060201. If you now subtract 1, you have 20060200, but there is no Feb 0. Go to our FAQ section and read the article on date arithemetic. Then switch to datecalc.

According to me the best method to date calculations is taking epcoh time but for that you need a c program i dont know if there is any unix function is there