How to look for the last file and rename it (sequencially, increment by one)

I need to Ftp a file to a UNIX directory from a windows directory, the file needs to be put sequencially in the UNIX directory , for example: I get the file from the windows directory with the following name.
EFT###.DAT, the script needs to look in the UNIX directory and if there are files, for example: eft710.dat, eft711.dat,eft712.dat. The new file that I just ftp needs to be rename as a eft713.dat keep incrementing by one.
Thank you in advance

Can the files arrive on the unix system from more than one source? If not, maintain a serial number file on the Windows system, and increment it with each transfer.
If there is a small number of sources, use a separate directory for each source.
Alternatively, if the files do not arrive more frequently than 1 a minute, use a different naming convention that ensures no duplicates, and periodically move the files from the receiving directory to a processing directory, and at this stage rename the files.

Is the ftp program on Windows or Unix? The answer may push you towards a path to solution.

Or, are you simply looking for a unix script to handle the rename of a file? For instance, ftp receive a file called my_new.dat that you want to rename to the next available sequential file number in pattern EFT###.dat

---------- Post updated at 10:50 AM ---------- Previous update was at 10:43 AM ----------

I've made two scripts.

First script is for ftp command in msdos, it's for get a filelist from the unix ftp server

---------- Post updated at 10:51 AM ---------- Previous update was at 10:50 AM ----------

comandos.ftp

open 192.168.253.7
user cnavarro |nC*d3W3
ls
bye

you muste execute with
C:\ftp -n -s:comandos.ftp > ftp.out

---------- Post updated at 10:54 AM ---------- Previous update was at 10:51 AM ----------

This generates ftp.out file, and must be "analyzed" for getting max id of files. For this I've created second file script

script.awk

/eft[0-9]*\.dat/{
    match($0,/[0-9]+/)
    n=0+substr($0,RSTART,RLENGTH)
    if (n>max){
        print n" es mayor que "max
        max=n
    }
}
END{
    print "open 192.168.253.7" > "upFile.ftp"
    print "user usuario password" > "upFile.ftp"
    print "put arch1 eft"(max+1)".dat" > "upFile.ftp"
    print "bye" > "upFile.ftp"
}

you must execute with:
c:\gawk --posix -f script.awk ftp.out

This generates a second ftp file you must run with:
C:\ftp -n -s:upFile.ftp > ftp.out

Sorry for multiedit but I can't post a reply, can anybody help me?

I've noticed that you cannot create two sequential posts. The second post is appended to the first and separated with a "post updated line"

You solution works, as long as there is a reasonable time gap between transmissions.

---------- Post updated at 11:20 AM ---------- Previous update was at 11:20 AM ----------

Good point, when I did it I just think in a static environment, and you propose a dynamic environment.

About my posts, if I press "Post reply" I write my message but it says is too short, even if I wrote more than 100 chars. I'm having a problem with vBulletin think because this is no the only forum where I face the problem, and the repetead factor is vBulletin.