Avatar of Balack
Balack asked on

How to use rsync to download files to another server?

There are 2 SUSE SLES11 servers in this setup. Both servers are located behinds firewall, and communicate through Internet. I intend to use rsync to frequently download the latest files from serverA to serverB. How should I setup the whole project? I heard that I can use SSH on top of rsync, is that right, and how it work?
Linux NetworkingLinux

Avatar of undefined
Last Comment

8/22/2022 - Mon


By default rsync will use ssh fot transport method. So if you have ssh connectivity between servers you can eaily acoomplish your transfer...

The syntax is straightforward:
to copy files from server a to b type
rsync filename username@serverB:/destination/directory

Open in new window

For detailed how-to try man rsync

What ports have to be opened in sender's and recipeint's firewalls?

Allowing tcp port 22 from source to destination (from A to B in my example) will be enough.
Your help has saved me hundreds of hours of internet surfing.

By the way to download file from server B you have to use command as follows:

rsync username@serverB:/directory/filename  /directory/

Open in new window

My first version was uploding to server B ....

I intends to schedule to run the rsync in cron job, and password prompt is not allowed. I heard that SSH is needed to setup with public and private keys. Is that true? If so, what are those steps?

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

use options..  rsync -alvzn   $localDir  host:$remoteDir

z = compress (speeds transfer between hosts)
n = Dry run, it will test the command only. rerun the same command without -n to execute it.
l = follow  symlinks
-a : Archive Mode

So you would use this command: rsync -alvzn rsync filename username@serverB:/destination/directory
Then, if everything passes,  run the same command without n:
rsync -alvz rsync filename username@serverB:/destination/directory
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

Sorry about the double post..    you use only 1 rsync (copy paste ftl)

rsync -alvzn filename username@serverB:/destination/directory #Test
rsync -alvz filename username@serverB:/destination/directory #actual command

Open in new window


I tested files/folders can be copied successfully. The main issue now is password prompting. How can I run without password prompting? As I intend to run it as a cron job.

Hi Ballack,
You can find detailed instructions on the link i provided...
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

It works like a charm