by Dibyendu Datta | March 13, 2024

How to Use SCP Command for File Transfer

How to Use SCP Command

The ability to securely transfer files is essential for both individuals and businesses. Whether you’re sharing sensitive documents, collaborating on projects, or managing server configurations, ensuring the confidentiality and integrity of your data during file transfers is paramount. SCP (Secure Copy Protocol), a command-line utility that operates over SSH (Secure Shell), provides a robust solution for secure file transfer. In this blog, we delve into SCP, exploring its functionality and effectiveness in secure data transmission, and emphasize how it ensures a reliable and encrypted transfer of files, making it a valuable tool.

In this blog, you'll gain insights into the SCP command’s functionality and uncover valuable tips and best practices for optimizing your file transfer workflows while ensuring security. Furthermore, in the final section, we share how CData Arc enables file transfers to your business partners using its SCP Connector.

What is SCP (Secure Copy Protocol)?

The Secure Copy Protocol (SCP) is a network protocol that enables secure file transfers between a local host and a remote host or between two remote hosts. It is based on the Secure Shell (SSH) protocol. SCP is known for its simplicity, security, and pre-installed availability.

Core principles of the SCP command

The SCP command, also known as secure copy, allows secure transfer of files between hosts. It uses the same authentication and security mechanisms as the SSH protocol. Here are some key principles:

  • Security: It uses SSH for data transfer and authentication, ensuring the authenticity and confidentiality of the data in transit.
  • Simplicity: It operates as a command-line utility, making it straightforward to use.
  • Pre-installed availability: It is typically pre-installed on many Unix-based systems, making it readily available.

Distinction between the SCP protocol and the command-line utility

While the terms SCP and secure copy are often used interchangeably, they refer to two related but distinct concepts:

  • The SCP protocol is a network protocol based on the BSD RCP protocol. It supports file transfers between hosts on a network and uses SSH for data transfer and authentication.
  • The SCP command is a command-line utility that implements the SCP protocol. It allows you to securely copy files and directories between two locations.

It’s important to note that while the SCP protocol provides the underlying framework for secure file transfers, the SCP command is the tool that users interact with directly to initiate these transfers.

The SCP command syntax

The SCP command is used to securely transfer files between systems. It uses SSH for data transfer and provides the same authentication and security as SSH.

Here is an example of a basic SCP command:

scp [options] source_username@source_host_ip:/path/to/source/file destination_username@destination_host_ip:/path/to/destination/directory

Let’s break down the command parameters:

  • options: Various options can be added to customize the SCP command. Common options include:
    -r: Recursively copies entire directories.
    -P: Specify the port number on the remote host.
    -i: Use a specific identity file for authentication.
  • source_username: The username for authentication on the source host.
  • source_host_ip: The IP address or domain name of the source host.
  • /path/to/source/file: The path to the file or directory on the source host that you want to transfer.
  • destination_username: The username for authentication on the destination host.
  • destination_host_ip: The IP address or domain name of the destination host.
  • /path/to/destination/directory: The path to the destination directory where you want to store the transferred file(s).

Example: scp -r -P 2222 -i ~/.ssh/private_key [email protected]:/path/to/source/file.txt [email protected]:/path/to/destination/directory

How to use SCP to copy files

The scp (secure copy) command is a powerful tool in Unix-like operating systems for securely transferring files between hosts. Below are different use cases for the SCP command:

1. Copy with SCP from the remote to the local system

The steps below provide detailed instructions, command syntax, and examples for using SCP to copy files from a remote system to a local one.

Step 1: Open a terminal window on your local system. This can be your computer or a server where you want to receive the files.

Step 2: The basic syntax for copying from remote to local using the SCP command is:

scp username@remote:/path/to/source/file /path/to/local/destination

Note: Replace username with your remote username, remote with the remote system's IP address or domain name, and provide the correct paths for the source and destination.

Step 3: You’ll be prompted to enter your password for the remote system. Alternatively, you can use key-based authentication for a more secure and password-less connection.

Step 4: SCP will display the progress of the file transfer, including the file size, percentage completed, and transfer speed.

Step 5: Once the transfer is complete, verify that the files have been successfully copied to the local destination.

Example: For instance, to copy a file named "example.txt" from a remote server with the IP address "192.168.1.1" to the local system's home directory, the command would be:

scp [email protected]:/path/to/example.txt ~/

2. Copy with SCP from the local to the remote system

To securely copy files from a local host to a remote system, follow the steps below:

Step 1: Launch a terminal window on your local system. This can be your computer or the server where the files are located.

Step 2: The basic syntax for copying from local to remote is:

scp /path/to/local/file username@remote:/path/to/remote/destination

Note: Replace /path/to/local/file with the local file path, username with your remote username, remote with the remote system's IP address or domain name, and provide the correct path for the remote destination.

Steps 3, 4, and 5 are the same as the steps demonstrated in the earlier section.

Example: For instance, to copy a file named "example.txt" from your local system to a remote server with the IP address "192.168.1.1" into the "/path/to/remote/destination" directory, the command would be:

scp /path/to/example.txt [email protected]:/path/to/remote/destination

3. Copy with SCP between two remote systems

To copy files from one remote host to another, follow the steps provided below:

Step 1: Launch a terminal window on your local system or a third server that has connectivity to both remote hosts.

Step 2: The basic syntax for copying from local to remote is:

scp username@source_host:/path/to/source/file username@destination_host:/path/to/destination

Note: Replace username with the appropriate usernames, source_host with the source host's IP address or domain name, destination_host with the destination host's IP address or domain name, and provide the correct paths for the source file and destination directory.

Steps 3, 4, and 5 are the same as the steps demonstrated in the earlier section.

Example: For instance, to copy a file named "example.txt" from a source remote system with the IP address "192.168.1.1" to a destination remote system with the IP address "203.0.113.2" into the "/path/to/destination" directory, the command would be:

scp [email protected]:/path/to/example.txt [email protected]:/path/to/destination

The CData difference

The SCP Connector from CData Arc supports secure and efficient file transfers to remote SSH servers as a part of your regular business to business communications. It ensures data transmissions are secure with SSH-enabled secure file transfer and robust 3DES encryption. The connector streamlines workflows by scheduling transfers, setting triggers, and defining conditions for file transfers. This level of automation and security in data transmission significantly enhances your workflows, making it an indispensable tool for your business seeking a reliable, secure, and flexible solution.

To experience the best-in-class data connectivity through a no-code user-friendly interface for your integration requirements, enhanced with additional functionalities such as EDI, MFT, and API workflows, seamlessly integrating with your application infrastructure whether it's in the cloud or on-premises — Sign up for a 30-day free trial!

As always, our support team is ready to answer any questions you have. Have you joined the CData Community? Ask questions, get answers, and share your knowledge in CData connectivity tools. Join us!

Try CData Arc today

Get a free 30-day trial of CData Arc to start automating and improving your EDI, MFT, and other B2B integration processes.

Get a trial