How do I copy a folder from remote to local host using scp
?
I use ssh
to log in to my server.
Then, I would like to copy the remote folder foo
to local /home/user/Desktop
.
How do I achieve this?
To copy the files you will need to first invoke the SCP, followed by the remote username@IP address, path to file. If you do not specify the path, it is assumed as default in this case which will be the user's home directory, this will be followed the path where the file will be stored locally.
Copy or Download a File From Remote to Local Using SCP SCP syntax is pretty simple. Just invoke SCP followed by the remote username, @, the IP address or host, colon, and the path to the file. If not specified, the default path is the remote user's home directory.
To copy a directory (and all the files it contains), use scp with the -r option. This tells scp to recursively copy the source directory and its contents. You'll be prompted for your password on the source system ( deathstar.com ).
Copy and paste the required file from the remote machine in the cloud storage disk. Now, the file will appear in the file transfer window as shown below. Click the download icon against the file. Now the file will be downloaded to your local machine.
scp -r [email protected]:/path/to/foo /home/user/Desktop/
By not including the trailing '/' at the end of foo, you will copy the directory itself (including contents), rather than only the contents of the directory.
From man scp
(See online manual)
-r Recursively copy entire directories
To use full power of scp you need to go through next steps:
Then, for example if you have this ~/.ssh/config:
Host test User testuser HostName test-site.com Port 22022 Host prod User produser HostName production-site.com Port 22022
you'll save yourself from password entry and simplify scp syntax like this:
scp -r prod:/path/foo /home/user/Desktop # copy to local scp -r prod:/path/foo test:/tmp # copy from remote prod to remote test
More over, you will be able to use remote path-completion:
scp test:/var/log/ # press tab twice Display all 151 possibilities? (y or n)
Update:
For enabling remote bash-completion you need to have bash-shell on both <source>
and <target>
hosts, and properly working bash-completion. For more information see related questions:
How to enable autocompletion for remote paths when using scp?
SCP filename tab completion
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With