Zum Inhalt springen

The SCP Command and how to use it 🧑‍💻💻

Recently at work, I had a task of developing and deploying an internal tool/application which basically lets us test certain playback stream URLs (DASH, HLS etc.) on Smart TVs using ShakaPlayer with Widevine DRM encryption.

So this application was deployed on one of our internal remote servers. There are a couple of other applications as well which are deployed on that remote server, but they had a simpler single-click deployment (pretty convenient 🙂).

As for this particular application, we had to deploy it manually by transferring the files from our local machine to the remote server (actually better because I got to learn something new 🤓).

The reason I shared the above story with you is that due to the above task, I got introduced to the SCP command in the Windows Command Line. Now I know that it may be a basic command for most of the experienced developers out there, but for me it was a new learning and I thought it would be nice sharing about it here and elaborating about how it is used.

Overview

SCP stands for Secure Copy Protocol. As the name pretty much suggests it is a command which is used to transfer directories/folders and files between 2 systems/locations using the SSH protocol. Now you may think that we already have the cp (copy) command for copying contents between locations 🤔, then what does SCP bring to the table ? The main advantage of SCP is that it ensures the data is encrypted 🔗⛓️ during the transfer.

File transfer

Different use cases of SCP command

There are multiple use cases of the SCP command, these include :-

  1. Copy/Transfer files from your local machine to a remote server.
  2. Copy/Transfer files from a remote server to your local machine.
  3. Copy/Transfer files between 2 remote servers.

Basic syntax of using the SCP command

scp [options] source-location destination-location

Example 1 => You want to copy a file ‚myFile.txt‘ present on your local machine to a remote server, you can execute the command like this :-

scp myFile.txt username@remote_server_host:/path/to/destination

This will copy myFile.txt to the specified destination in the remote server.

Example 2 => You want copy a file ‚myFile.txt‘ present on your remote server to your local machine, you can execute the command like this :-

scp username@remote_server_host:/path/to/myFile.txt /local_machine/destination

This will copy myFile.txt to the specified destination on your local machine.

Example 3 => You want to copy a file ‚myFile.txt‘ present on one remote server to another remote server, you can execute the command like this :-

scp username@remote_server_host1:/path/to/myFile.txt username@remote_server_host2:/path/to/destination

This will copy myFile.txt from remote_server_host1 to the specified destination in remote_server_host2.

Different options which can be used with the SCP command

  1. -r => used to recursively copy entire folders/directories
  2. -v => used to switch to verbose mode i.e. while copying it will show the progress and debug information
  3. -C => used to compress the data during copy/transfer
  4. -q => used to switch to quite mode i.e. while copying it will not show any progress or error messages.

SCP

Important points to consider regarding SCP command

  1. SCP primarily operates over SSH, so you will need to have SSH access to the target remote server.
  2. Before using the SCP command, ensure that the remote server has SSH enabled and you also have appropriate permissions.

And that’s it! This was just a quick overview about the basics of the SCP command, how and when to use it and more.

Connect with me on LinkedIn :- Linkedin

Do check out my GitHub for amazing projects :- Github

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert