Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying files using rsync from remote server to local machine

Tags:

ssh

rsync

Once I've ssh'd into my remote server, what would the command be to copy all files from a directory to a local directory on my machine?

like image 708
markstewie Avatar asked Feb 01 '12 04:02

markstewie


People also ask

How do I transfer files from rsync to local?

Copy a single file locally If you want to copy a file from one location to another within your system, you can do so by typing rsync followed by the source file name and the destination directory. Note: Instead of “/home/tin/file1. txt”, we can also type “file1” as we are currently working in the home directory.

Can I use rsync to copy files?

Rsync (Remote Sync) is the most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems.

How do I use rsync with FTP?

Short answer – You can't. rsync can't use ftp as a remote host. So rsync does not work over ftp session/protocol.


2 Answers

From your local machine:

rsync -chavzP --stats [email protected]:/path/to/copy /path/to/local/storage 

From your local machine with a non standard ssh port:

rsync -chavzP -e "ssh -p $portNumber" [email protected]:/path/to/copy /local/path 

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

rsync -chavzP --stats /path/to/copy [email protected]:/path/to/local/storage 

See man rsync for an explanation of my usual switches.

like image 132
Johnsyweb Avatar answered Sep 29 '22 14:09

Johnsyweb


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

scp user@host:/path/file /localpath/file 

Wild card characters are supported, so

scp user@host:/path/folder/* /localpath/folder 

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.

like image 20
Tezyn Avatar answered Sep 29 '22 14:09

Tezyn