SCP file and directory in linux and Unix like operating system

SCP stands for secure copy.It is based upon SSH (Secure Shell) protocol.SCP is used for securely transferring the files between local and remote system.
Note: If SSH service is not running or deny by firewall or IPTABLES of system then SCP will also not work.

Syntax:
scp SOURCE-FILE-LOCATION TARGET-LOCATION

(1) SCP file from local to remote system

Run the below given command from your system

scp filename remote-username@remote-ip-address:/path/to/transfer/file

eg.


scp test.txt sharad@192.168.1.19:/tmp

(2) SCP Directory from local to remote system

Run the below given command from your system

scp -r directory-name remote-username@remote-ip-address:/path/to/transfer/directory

eg.


scp  -r testdir sharad@192.168.1.19:/tmp

(3) SCP file from remote to local system

Run the below given command from your system

scp remote-username@remote-ip-address:/path/of/target-FILE /path/in/your/localSystem

eg.


scp sharad@192.168.1.19:~/test.txt  ~/Desktop

(4) SCP directory from remote to local system

Run the below given command from your system

scp remote-username@remote-ip-address:/path/of/target-DIRECTORY /path/in/your/localSystem

eg.


scp -r sharad@192.168.1.19:~/testdir  ~/Desktop

If SSH port no. is changed from port no. 22 to other one

SSH port no. = 2211

(Note: SSH port no. might be different in your case hence give your ssh port no. instead of 2211)

Syntax:
scp -P port.no SOURCE-FILE-LOCATION TARGET-LOCATION

(1A) SCP file from local to remote system

Run the below given command from your system

scp -P port.no. filename remote-username@remote-ip-address:/path/to/transfer/file

eg.


scp-P 2211 test.txt sharad@192.168.1.19:/tmp

(2A) SCP Directory from local to remote system

Run the below given command from your system

scp -P port.no -r directory-name remote-username@remote-ip-address:/path/to/transfer/directory

eg.


scp  -p 2211 -r testdir sharad@192.168.1.19:/tmp

(3A) SCP file from remote to local system

Run the below given command from your system

scp -P port.no remote-username@remote-ip-address:/path/of/target-FILE /path/in/your/localSystem

eg.


scp -P 2211 sharad@192.168.1.19:~/test.txt  ~/Desktop

(4A) SCP directory from remote to local system

Run the below given command from your system

scp -P port.no remote-username@remote-ip-address:/path/of/target-DIRECTORY /path/in/your/localSystem

eg.


scp -P 2211-r sharad@192.168.1.19:~/testdir  ~/Desktop

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.