Thursday, March 26, 2015

scp : Command usage with examples

 

SCP Command Examples:


Let see the examples of scp command in unix or linux system.
1. Copying with in the same system
You can use the scp command just like the cp command to copy files from one directory to another directory.

scp Unix-storage.dat /var/tmp/

This command copies the file unix-storage.dat from current directory to the /var/tmp directory.
2. Copy file from local host to remote server
This is most frequently used operation to transfer files in unix system.

scp filename user@remotehost:/remote/directory/

This command connects to the remote host and copies the specified file to the /remote/directory/.
3. Copy files from remote host to local server.
This operation is used when taking backup of the files in remote server.

scp user@remotehost:/usr/backup/oracle_backup.dat .

This command copies the oracle backup file in the remote host to the current directory.
4. Copying files between two remote servers
The scp command can also be used to copy files between two remote hosts.

scp source_user@source_remote_host:/usr/bin/mysql_backup.sh target_user@target_remote_host:/var/tmp/

The above command copies the mysql bakup shell script from the source remote host the /var/tmp directory of target remote host.
5. Copying a directory.
To copy all the files in a directory, use the -r option with the scp command. This makes the scp command to copy the directory recursively.

scp -r directory user@remotehost:/var/tmp/

The above command copies the directory from local server to the remote host.
6. Improving performance of scp command
By default the scp command uses the Triple-DES cipher/AES-128 to encrypt the data. Using the blowfish or arcfour encryption will improve the performance of the scp command.

scp -c blowfish filename  user@remoteserver:/var/
scp -c arcfour localfile user@remoteserver:/var/

7. Limit bandwidth
You can limit the bandwidth used by the scp command using the -l option.

scp -l bandwidth_limit filename user@hostname:/usr/backup/
Here bandwidth_limit is numeric to be specified in kilobits per second.

8. Specifying the port number
We can make the scp command to copy the files over a specified port number using the -P option.
scp -P 6001 storage_backup.bat username@hostname:/tmp/

No comments:

Post a Comment