How do I copy a folder from remote to local host using scp
?
I use ssh
to log in my server.
Then, I would like to copy the remote folder foo
to local /home/user/Desktop
.
How do I achieve this?
How do I copy a folder from remote to local host using scp
?
I use ssh
to log in my server.
Then, I would like to copy the remote folder foo
to local /home/user/Desktop
.
How do I achieve this?
scp -r user@your.server.example.com:/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
To copy all from Local Location to Remote Location (Upload)
scp -r /path/from/local username@hostname:/path/to/remote
To copy all from Remote Location to Local Location (Download)
scp -r username@hostname:/path/from/remote /path/to/local
Custom Port where xxxx
is custom port number
scp -r -P xxxx username@hostname:/path/from/remote /path/to/local
Copy on current directory from Remote to Local
scp -r username@hostname:/path/from/remote .
Help:
-r
Recursively copy all directories and files/
, Get full location by pwd
scp
will replace all existing fileshostname
will be hostname or IP address-P portnumber
Note: Sometimes the custom port will not work due to the port not being allowed in the firewall, so make sure that custom port is allowed in the firewall for incoming and outgoing connection
What I always use is:
scp -r username@IP:/path/to/server/source/folder/ .
. (dot) : it means current folder
. so copy from server and paste here only.
IP : can be an IP address like 125.55.41.311
or it can be host like ns1.mysite.com
.
Better to first compress catalog on remote server:
tar czfP backup.tar.gz /path/to/catalog
Secondly, download from remote:
scp user@your.server.example.com:/path/to/backup.tar.gz .
At the end, extract the files:
tar -xzvf backup.tar.gz
And if you have one hell of a files to download from the remote location and if you don't much care about security, try changing the scp default encryption (Triple-DES) to something like 'blowfish'.
This will reduce file copying time drastically.
scp -c blowfish -r user@your.server.example.com:/path/to/foo /home/user/Desktop/
Typical scenario,
scp -r -P port username@ip:/path-to-folder .
explained with an sample,
scp -r -P 27000 abc@10.70.12.12:/tmp/hotel_dump .
where,
port = 27000
username = "abc" , remote server username
path-to-folder = tmp/hotel_dump
. = current local directory
Go to Files on your unity toolbar
Press Ctrl + l and write here_goes_your_user_name@192.168.10.123
The 192.168.1.103 is the host that you want to connect.
The here one example
The question was how to copy a folder from remote to local with scp
command.
$ scp -r userRemote@remoteIp:/path/remoteDir /path/localDir
But here is the better way for do it with sftp
- SSH File Transfer Protocol (also Secure File Transfer Protocol, or SFTP) is a network protocol that provides file access, file transfer, and file management over any reliable data stream.(wikipedia).
$ sftp user_remote@remote_ip
sftp> cd /path/to/remoteDir
sftp> get -r remoteDir
Fetching /path/to/remoteDir to localDir 100% 398 0.4KB/s 00:00
For help about sftp
command just type help
or ?
.
In case you run into "Too many authentication failures", specify the exact SSH key you have added to your severs ssh server:
scp -r -i /path/to/local/key user@remote.tld:/path/to/folder /your/local/target/dir
I don't know why but I was had to use local folder before source server directive . to make it work
scp -r . root@888.888.888.888:/usr/share/nginx/www/example.org/
For Windows OS, we used this command.
pscp -r -P 22 hostname@IP:/path/to/Downloads ./
Retrieved from : http:www.stackoverflow.com/questions/11304895/how-do-i-copy-a-folder-from-remote-to-local-using-scp
How to get the current branch name in Git? (0) | 2023.06.08 |
---|---|
"Least Astonishment" and the Mutable Default Argument (0) | 2023.06.08 |
How do you disable browser autocomplete on web form field / input tags? (0) | 2023.06.08 |
How can I change an element's class with JavaScript? (0) | 2023.06.08 |
How can I upload files asynchronously with jQuery? (0) | 2023.06.08 |