Thanks for your reply, Rename is a ftp command. I already compared the versions, it seems fine. Would like to understand why it is behaving differently.
I suspect the difference arises from the remote ftp code's rename command being implemented two different ways on the remote servers:
system 1
call the equivalent of C:
system ("mv oldfilename newfilename")
This would mean invoking the /bin/sh shell on the remote machine, which in turn would see a '#' character as a comment, which requires your escape "\" fix.
system 2
call the mv syscall or the C standard library's rename library call - this never invokes /bin/sh so no shell is called.
Note: /bin/sh can be a completely different object on different machines - it is NOT necessarily the shell that you use to run the ftp script locally.