Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Secure copy files across hosts
- ### 1.Transfer single file
- Open GIT BASH (to use Secure Copy), type below commands.
- ```
- $cd /e/xampp/htdocs/projname
- $touch README.md
- ```
- To copy single file from local machine to remote machine in target directory
- ```
- $scp -v README.md user@xx.xxx.xxx.xx:/var/www/projname
- ```
- To copy single file from remote machine to local machine in current working directory(.)
- ```
- $scp -v user@xx.xxx.xxx.xx:/var/www/projname/file.txt .
- ```
- ### 2. Transfer multiple files
- To copy multiple files from local directory to remote host
- ```
- $scp foo.txt bar.txt user@xx.xxx.xxx.xx:/var/www/projname
- ```
- To copy multiple files from remote host to current local directory
- ```
- $scp user@xx.xxx.xxx.xx:/var/www/projname/\{foo.txt,bar.txt\} .
- ```
- To copy an entire directory recursively from one host to another use the r switch and specify the directory
- ```
- $scp -v -r ~/Downloads user@xx.xxx.xxx.xx:/var/www/projname
- ```
- ### 3. Speed up the transfer with compression
- A super cool option to speed up the transfer to save time and bandwidth. All you need to do is use the C option to enable compression. The files are compressed on the fly and decompressed on the destination.
- ```
- $scp -vrC ~/Downloads user@xx.xxx.xxx.xx:/var/projname
- $scp -vrC user@xx.xxx.xxx.xx:/var/www/projname/dirname .
- ```
- In the above example we moved the entire directory with compression enabled. The speed gain would depend on how much the files could be compressed.
- ### 4. Copy files across 2 remote hosts
- ```
- $scp user1@remotehost1:/some/remote/dir/foobar.txt user2@remotehost2:/some/remote/dir/
- ```
- #### Note:
- -v is verbose output (optional flag)
- -r is recursive flag
- -c is compression flag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement