Help with renaming files in remote server

I have to write a script to get some files from remote server using FTP and rename it after the FTP. I use wildcard to get the file as i do not no the exact file name or the number of files in the remote server.

My script is similar to the following...

#!/bin/sh
LOG=/Log/ftp.log
ftp (FTP server) <<EOF
ls ABC*.dat list.txt >> $LOG
mget ABC*.dat >> $LOG
bye
EOF

I read from previous post that a rename is not possible with wildcard. And someone else suggested using a list to get the files in the remote server and try to rename it with that.

But i did not find how to do that. Could any of you help me in this?

Thank you.