SCP file transfer between two linux machine in command line

SCP (Secure Copy) is a command line tool for Linux systems to securely transfer files from local to remote server or vice a versa. SCP uses SSH protocol for transferring files between two systems which is more secure than ftp.

Syntax: (Local to Remote)

scp /path/to/local/file.txt user@192.168.10.100:/remote/path/

Syntax: (Remote to Local)

scp user@192.168.10.100:/remote/file.txt /path/to/local/

SCP command required password of remote system. In case you need to configure scp command in script and run with scheduler, you need to configure key based ssh login.

Transfer File Local to Remote Server
Following command will copy myfile.txt from current directory of local system to remote server’s /opt directory using root authentication. We are assuming remote server hostname is example.com.

$ scp myfile.txt root@example.com:/opt/

Transfer File Remote Server to Local
Following command will copy /opt/myfile.txt from remote system to local system’s /opt directory.

$ scp root@example.com:/opt/myfile.txt /opt/

Define Port with SCP Command
In case SSH is running on different port on remote server, use -P switch followed by port number with scp command.

$ scp -P 2344 myfile.txt root@example.com:/opt/myfile.txt

Transfer Directory Local to Remote Server Recursively
Following command will copy /opt/mydir directory from local system to remote system’s /opt directory recursively.

$ scp -r /opt/mydir root@example.com:/opt/

Transfer Directory Remote Server to Local Recursively
Following command will copy /opt/mydir directory from remote system to remote system’s /opt directory recursively.

$ scp -r root@example.com:/opt/mydir /opt/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s