Securely Transfer Files From or to a Remote Server Using SCP

How to use secure copy protocol

Prashant Sharma
Apr 14 · 2 min read
Image for post
Image for post
Photo by Laika Notebooks on Unsplash

The SCP (secure copy protocol) is a network protocol, based on the BSD RCP protocol, that supports file transfers between hosts on a network. SCP uses secure shell (SSH) for data transfer and the same mechanisms for authentication.

Using SCP, you can copy file/directory from:

  • your local machine to a remote system
  • a remote system to your local system
  • one remote system to another remote system from your local system

While transferring data using SCP, files and passwords are encrypted so that anyone snooping on the traffic doesn’t get anything sensitive.

Things to keep in mind before you start:

  • The scp command relies on SSH for transferring the data, so it requires an SSH key or password to authenticate on the remote systems.
  • To be able to copy file/directory, you must have at least read permissions on the source file and write permission on the target system.


The syntax for the scp command is:

scp [options] username@source_host:directory/filename  /where/to/put

In the examples below, I recursively copy entire directories.


From remote to local

scp -r username@ipaddress:/directory/to/send /local/where/to/put

From local to remote

scp -r /local/directory/to/send username@ipaddress:/where/to/put

Copying between two remote hosts

scp -r username@ipaddress1:/file/to/send username@ipaddress2:/where/to/put

You can use scp with the following options according to your requirements.


scp –P port — Generally, 22 is used as the default port of scp. You can also specify a specific port.
scp –p — An estimated time and the connection speed will appear on the screen.
scp –q — Disable progress meter and warning.
scp –r — Recursively copy entire directories.
scp –v — Print debug information into the screen. It can help you in debugging connection, authentication, and configuration problems.
scp -c — By default, SCP using AES-128 to encrypt files. If you want to change to another cipher to encrypt it, you can use -c.

I hope that you now have understood how to make the best use of the scp command to securely transfer files between the systems.

If you have any suggestions on your mind, please let me know in the comments. And if you know any other awesome features of the scp command, do share with us.

Better Programming

Advice for programmers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store