How do you compare two folders and copy the difference to a third folder in a remote server?

How do you compare one local folder and a remote folder and copy the difference to a third folder in a remote folder.e.g.

Folder A -- Is in a remote server and it has the following files

TEST1.OUT
TEST2.OUT
TEST3.OUT

Folder B --Is in a local server and it has the following files

TEST1.OUT
TEST2.OUT
TEST 3.OUT
TEST4.OUT
testtest123.out

comparison is done based on timestamp.


THIRD Folder - Holds new files that are not in remote server

TEST4.OUT
testtest123.out

Your question is unclear: First, you say that you compare by timestamp, and then you say that you want to copy only files that are not on the remote server. For example, if TEST2.OUT on the local server is younger than TEST2.OUT on the remote server, should it be copied or not?

In any case, have a look at rsync.

How can you use rsync to compare local directory and remote directory and then copy the difference to a new directory in remote serve?

E.g I can't get it to work with this command.

rsync -rvcm --compare-dest=/tmp/test server.com:/tmp/test server.com:/tmp/difference

It's rsync, not Rsync.

The comparing is done implicitly, so you don't need a separate comparision step. You basically just do a rsync source destination , and rsync figures out by itself, what it needs to copy. To specify, what are the exact conditions, under which a file should be copied, is defined by the options which can be passed to rsync.

I know how to use rsync to sync up remote destination folder but my requirement is to compare files in local directory to files in remote directory and copy the difference to another directory in same remote server named difference.

That's why I gave an example of a rsync command, I need an example command on how this can be accomplished.

e,g,

rsync -rvcm --compare-dest=/tmp/test server.com:/tmp/test server.com:/tmp/difference 
       Any help is highly appreciated.

You mean: You have a local directory A, and remote directories B and C, and want to copy those files in A to be copied to C, which are different from B? Sorry to misunderstand you.

In this case you indeed need to rule out your own algorithm, but unless I overlook something, you haven't answered yet my earlier question, how you exactly define "difference". Content? Last modification time?

You still can use rsync for getting the difference. Please look at the --dry-run switch of rsync. The idea is to first do a dry run of rsync of A vs. B, collect from it the names of the files which would be copied, and then use this list to actually copy the files to B, using for instance scp or rcp.