Copiar archivos usando rsync desde el servidor remoto a la máquina local

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?

preguntado el 01 de febrero de 12 a las 04:02

Porque tú puedes rsync directly from your local machine. -

Oh... yes I can. I see the other answers now. Thanks. -

This is common task for (web) development with a good answer. I don't see why it is still closed. -

I think @d.raev was referring to the fact that the question was closed as off topic (if I recall correctly I flagged for this question to be migrado to SuperUser, where I think it fits better) rather than that there was no accepted answer. Still... it was nice to have my answer accepted after all this time. :-) -

@markstewie no bad feelings, it is a good question and it helped me (seems many others too) but this "closed" make it look not trust worthy so I wonted to bring some attention to it. -

3 Respuestas

From your local machine:

rsync -chavzP --stats user@remote.host:/path/to/copy /path/to/local/storage

From your local machine with a non standard ssh port:

rsync -chavzP -e "ssh -p $portNumber" user@remote.host:/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 user@host.remoted.from:/path/to/local/storage

Consulte nuestra página man rsync for an explanation of my usual switches.

Respondido 13 Feb 18, 17:02

An explanation of the command: explicahell.com/… - beefsack

Wow that explainshell site is awesome. - gosukiwi

@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

Be careful when rsyncing with trailing slashes. The command given by Johnnysweb would create a directory called copy inside /path/to/local/storage. Al igual que /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. - tío

I came here for an rsync command and I came away with explainshell.com. Thanks @beefsack! - Cyphase

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.

Respondido el 21 de junio de 15 a las 06:06

¿Por qué utilizar scp más bien que rsync? Also, watch that your shell doesn't try to expand user@host:/path/folder/*, perhaps by using single quotes ('). - Johnsyweb

yo se que 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 y la is often faster and more efficient than scp. - Johnsyweb

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

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

Also rsync is much faster than scp. - Mostafa Hadian

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

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

rsync -avP -e "ssh -i /home/local_user/ssh/key_to_access_remote_server.pem" remote_user@remote_host.ip:/home/remote_user/file.gz /home/local_user/Downloads/

Dónde v opción es --verbose, a opción es --archive - archive mode, P option same as --partial - keep partially transferred files, e opción es --rsh=COMMAND - specifying the remote shell to use.

rsync man page

Respondido 11 Feb 21, 11:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.