DEV Community

Vuyisile Ndlovu
Vuyisile Ndlovu

Posted on • Originally published at vuyisile.com on

SCP: Sending files between servers using SSH

SCP or Secure Copy is a useful program for sending files between two or more computers over a secure shell (SSH) connection. In this post, I’ll show you how to use SCP to send files from your local computer to a remote, copy files from a remote computer to your local or copy files between two servers.

An SCP command has the following basic structure:

scp [OPTION] [user@src_host:] file1 [user@dest_host"] file2
Enter fullscreen mode Exit fullscreen mode

Where OPTION refers to the optional flags you can pass to scp such as the following:

  • -P remote host SSH port
  • -p preserve file modification and access times
  • -q quiet
  • -C compress
  • -r copy directories recursively

The colon ( : ) that comes after the host IP address or domain name is important.

Sending a file from the local computer to a remote computer

scp file.txt remote_username@host1.com:/path/to/remote/dir

Copy a file from the remote computer to the local computer

scp remote_username@host1.com:/path/to/file.txt /local/directory

Copy files between TWO remote computers

scp user1@host1.com:/path/to/file.txt user2@host2.com:/path/to/file/location

Secure copy to an EC2 instance without password

scp -i mykey.pem somefile.txt root@my.ec2.id.amazonaws.com:/

Image of Bright Data

Ensure Data Quality Across Sources – Manage and normalize data effortlessly.

Maintain high-quality, consistent data across multiple sources with our efficient data management tools.

Manage Data

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay