SCP Command Line Examples – Transferring files from one Linux host to another

Table of Contents

What is SCP Command Lines?

SCP stands for Secure Copy Protocol. It is a command-line tool for securely copying files between computers. It uses the SSH protocol to transfer data, which provides secure encrypted communications between two untrusted hosts over an insecure network. The scp command can be used to copy files between a local and remote server, or between two remote servers. It has the same syntax as the cp command and can be used in a similar way, but with the added security provided by SSH.

scp [source file] [destination]:

This command is used to copy a file from the source location to the destination. For example, to copy a file named “file.txt” from the local machine to a remote machine with IP address 192.168.1.100, the command would be:

				
					scp file.txt user@192.168.1.100:/home/user/

				
			

scp -r [source directory] [destination]:

This command is used to copy a directory and its contents from the source location to the destination. The -r option stands for “recursive”. For example, to copy a directory named “myfiles” and its contents from the local machine to a remote machine with IP address 192.168.1.100, the command would be:

				
					scp -r myfiles user@192.168.1.100:/home/user/

				
			

scp -P [port number] [source file] [destination]:

This command is used to specify a different port number for the connection. By default, SCP uses port 22. For example, to copy a file named “file.txt” from the local machine to a remote machine with IP address 192.168.1.100 on port 2222, the command would be:

				
					scp -P 2222 file.txt user@192.168.1.100:/home/user/

				
			

scp -p [source file] [destination]:

This command is used to preserve the modification times, access times, and modes from the original file. For example, to copy a file named “file.txt” from the local machine to a remote machine with IP address 192.168.1.100, preserving the original timestamps, the command would be:

				
					scp -p file.txt user@192.168.1.100:/home/user/

				
			

scp -q [source file] [destination]:

This command is used to suppress the progress meter and warning messages. For example, to copy a file named “file.txt” from the local machine to a remote machine with IP address 192.168.1.100, without displaying progress or warnings, the command would be:

				
					scp -q file.txt user@192.168.1.100:/home/user/

				
			

Note that all the above examples assume that you have the necessary login credentials for the remote machine and that the remote machine has the SCP service running.

 

Table of Contents

Join the thousands of websites that trust Koerge.

Subscribe

Receive WordPress tips, tricks and news straight to your inbox every week.