I am looking to automate the transfer of file in a given directory from one server to another server. they are both on the same network, can ping each-other, and even ssh from one to another.

Currently my methodology is sshing into Server A, pull the files down, SSH into Server B and upload them...

I already saw an article here, But I wanted to ask you guys what is the best way to transfer files from server to server, for embedding in a cron-job, or automating.

Here are my limitations:

  • Neither server can have any public web services (no port 80, no apache, nothing sadface )

  • Neither server can use any sort of FTP connection (although we can ssh)

Thank you all in advance for your help


5 Answers 5


Here is already many answers about scp or rsync. For routine "cron based" backup is rsync better.


  • rsync copying only files what are not already at the target
  • so, usually a bit faster than scp -r
  • has a bunch of useful parameters (e.g. what to do with symlinks and etc)
  • with some tweaking can act as "OS X" time machine (hardlinking the latest versions)
  • you can run rsync over the ssh, or by rsync daemon (but this is need much more config)
  • has a --dry-run arg to show what will copy - nice for developemnt/debugging.

for the simple use try:

rsync --dry-run -azvv -e ssh remoteuser@remotehost:/remote/path /local/dir

one can add --delete for deleting files what are not exists at remote, and soo... man is your friend.

Ps voting to close, because this belong to superuser.

  • Thank you for explaining in more detail the advantages. I had known about SCP, but was looking for informative posts like this one, thank you again
    – Beau Bouchard
    Jun 13, 2012 at 16:50

if ssh is working between the servers, scp seems to be what you're looking for. it's as easy as:

scp /dir/source.file user@targethost:dir/target.file
  • 1
    rsync may work better as it will only transfer the parts of the file that have been updated. Depends whether the entire file is changing or whether it's just parts of it I guess
    – Paul Bain
    Jun 13, 2012 at 15:47

Looks like a job for SCP (Secure Copy Protocol)

  • I read somewhere that this isn't the best way. Got any insight to share?
    – Keyser
    Jun 13, 2012 at 15:46

Use http://en.wikipedia.org/wiki/Rsync or http://en.wikipedia.org/wiki/Scp

  • No need to repost this info. Also, going for cheap rep will take away the great feeling of reaching 10k on your own. Edit: No one actually posted rsync in an answer, so it's kind of ok.
    – Keyser
    Jun 13, 2012 at 15:49
  • 3
    @John Conde & AlexeyKa - Guys, do you really believe than for SO is the best ending as an link-collection to somewhere in the inet? Try add some explanation, something what comes from your experience. You must not be en expert, but adding only links from wikipedia is shallow. Im new in SO, so if i'm wrong - appologize me.
    – cajwine
    Jun 13, 2012 at 16:41

Is SMB an option? You could simply cp the files to a shared folder.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .