Copying Files using Rsync from Remote Server to Local Machine

4 min read
05 September 2022

Trending sort is based off of the default sorting method - by highest score - but it boosts votes that have happened recently, helping to surface more up-to-date answers.


It falls back to sorting by highest score if no posts are trending.


From your local machine:


From your local machine with a non standard ssh port:


Or from the remote host, assuming you really want to work this way and your local machine is listening on SSH:


See man rsync for an explanation of my usual switches.


- 334


An explanation of the command: explainshell.com/… - beefsack
Aug 16, 2014 at 6:42


- 158


Wow that explainshell site is awesome. - gosukiwi
Jan 8, 2015 at 22:59


@cmcdragonkai: indeed, the local host must be running an ssh server and be accessible to the remote host. This is one of the reasons that I prefer the first solution over the second. - johnsyweb
Feb 22, 2015 at 20:00


- 24


Be careful when rsyncing with trailing slashes. The command given by Johnnysweb would create a directory called copy inside /path/to/local/storage. Like so /path/to/local/storage/copy. If that's what you want great. However a more common scenario is you want to copy the contents of the remote directory into a directory in your local. Then you would do /path/to/copy/ which would place the contents inside the directory /path/to/local/storage without creating a local copy directory. - chap
Oct 21, 2015 at 5:22


- 21


I came here for an rsync command and I came away with explainshell.com. Thanks @beefsack! - Cyphase
Feb 23, 2017 at 6:56


If you have SSH access, you don't need to SSH first and then copy, just use Secure Copy (SCP) from the destination.


Wild card characters are supported, so


will copy all of the remote files in that folder.If copying more then one directory.


note -r will copy all sub-folders and content too.


- 7


Why use scp rather than rsync? Also, watch that your shell doesn't try to expand user@host:/path/folder/*, perhaps by using single quotes ('). - johnsyweb
Feb 1, 2012 at 19:37


- 8


I know what scp is, that wasn't my question. Why didn't you use rsync? This is what is what the question asks for, doesn't require an established SSH session and is often faster and more efficient than scp. - johnsyweb
Feb 2, 2012 at 4:49


- 27


Remember, scp follows symlinks instead of copying them. This can lead to copying more then you expect and in loss of symlinks (they become normal folders/files). - Mondane
Jan 26, 2014 at 10:59


- 2


Mondane's response is precisely the reason I found this post. Normally, I use scp for everything, but I needed to preserve permissions and symlink from server to server. Also, the speed difference (bc my newbie self definitely scped first) was vast. - kyle
May 1, 2014 at 13:30


- 1


Also rsync is much faster than scp. - Mostafa Hadian
Dec 3, 2020 at 8:40


I think it is better to copy files from your local computer, because if files number or file size is very big, copying process could be interrupted if your current ssh session would be lost (broken pipe or whatever). Ua-7.com


If you have configured ssh key to connect to your remote server, you could use the following command:


Where v option is --verbose, a option is --archive - archive mode, P option same as --partial - keep partially transferred files, e option is --rsh=COMMAND - specifying the remote shell to use.


rsync man page


Your Answer


Thanks for contributing an answer to Stack Overflow!


- Please be sure to answer the question. Provide details and share your research!


But avoid …


- Asking for help, clarification, or responding to other answers.

- Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.


Sign up or log in


Post as a guest


Required, but never shown


By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy


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

In case you have found a mistake in the text, please send a message to the author by selecting the mistake and pressing Ctrl-Enter.
Groth Hebert 0
Joined: 1 year ago
Comments (0)

    No comments yet

You must be logged in to comment.

Sign In / Sign Up