I did achieved this by using the rename function, and if the rename function throws an error back the file doesn't exist.
Ouch.
You really can't make that conclusion. The rename function may have failed (throws an error back) because you simply are not allowed to rename a file - that is, the file does exist but the FTP server does not allow you to rename it. Could also be that the file exists but the name you are trying to rename it to is not valid. You simply cannot conclude that a file does not exist just based on rename failing. Also, if rename succeeds you have now renamed the file - are you sure you want to do that?
This seems to me like a very wrong way to go about this.
Why don't you just:
a) request a directory listing and see if the file is in the list.
b) try to RETRieve the file and check if that succeeds.
c) ask for the
SIZE of the file and check the returned value.
See also
RFC 959.