FTP rename command help

I have to ftp and rename the file with #finished# extension after successfully transfer. In some environments the command

rename ABCD.dat ABCD.#finished#

is working fine, but some environments its not working, I have to use escape character something like :

rename ABCD.dat ABCD.\#finished\#

Why is it behaving differently? Both servers are running on Linux same version and korn shell.

Thank you in advance for your help.

rename is neither a linux nor a ksh command/builtin. It's either an ftp command or a perl script. Compare the versions of either.

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.

1 Like