Not so long ago I was looking into a bash script that used SFTP’s rename command to move file on a remote server from one directory to another. No matter what, the script would always fail with an error from SFTP, that went something like “Unable to rename file”.

The same script worked just fine on another server. That server was supposedly identical to the one I was trying to debug. I had tried a bunch of things to find out what was going on. Both servers were running RedHat 5 with SSH version 4.3p2-82.el5 from RedHat.

Finally, I attached strace to running sftp-server process and launched the script again. Here is what strace returned:

Process 5848 attached - interrupt to quit
select(5, [3], [], NULL, NULL)          = 1 (in [3])
read(3, "\0\0\0\200\22\0\0\0\2\0\0\0)/data/load/temp/pro"..., 16384) = 132
lstat("/data/load/temp/probe1/loader20120929.txt", {st_mode=S_IFREG|0777, st_size=9, ...}) = 0
link("/data/load/temp/probe1/loader20120929.txt", "/data/load/prd/datfiles/probe1/20120929/20120929_100602/loader20120929.txt") = -1 EXDEV (Invalid cross-device link)
select(5, [3], [4], NULL, NULL)         = 1 (out [4])
write(4, "\0\0\0\30e\0\0\0\2\0\0\0\4\0\0\0\7Failure\0\0\0\0", 28) = 28
select(5, [3], [], NULL, NULL <unfinished ...>

Interesting… It turned out that the server script did not work on had source and destination directories on different mount points. I tried to find out why that would matter or if this is a bug, but I did not manage to find anything.