Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

migrated from stackoverflow.com Jun 14 '12 at 4:02

This question came from our site for professional and enthusiast programmers.

5  
rsync is your friend here! that will work over SSH if you create a key on both servers! Check out this article: ubuntuforums.org/showthread.php?t=238672 –  Paul Bain Jun 13 '12 at 15:45

5 Answers 5

up vote 8 down vote accepted

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

Reasons:

  • 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.

share|improve this answer
    
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 '12 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
share|improve this answer
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 '12 at 15:47

Looks like a job for SCP (Secure Copy Protocol)

share|improve this answer
    
I read somewhere that this isn't the best way. Got any insight to share? –  Keyser Jun 13 '12 at 15:46

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

share|improve this answer
    
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 '12 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 '12 at 16:41

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.