Secure Shell (SSH) has been used for many years to remotely access systems, and a common need has been to transfer files to those systems, along with a standard terminal connection.
Secure Copy Protocol (SCP) was developed to utilize the same SSH mechanism to transfer files between servers. SCP is available with most SSH clients that are commonly preinstalled on most Linux operating systems.
If you would like to use SCP on Windows, it is usable by installing the OpenSSH Client feature for Windows. There are third party packages that can provide the executable, but as of Windows 10, this is the most convenient method and often installed by default.
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
SCP has a number of options to enable controlling the connection and suit most connection scenarios.
These options are relevant to the 8.3 release of SCP.
As you can see there are a large number of options that make it easy to configure your connection to make even the most complex of connections work properly.
The simplest example is by transferring files from one server to another.
scp ~/backup.tar root@server:~/backup.tar
Of course, this assumes an extremely simple server connection. Oftentimes you may have a more complex connection with different ports and using a public/private key.
scp -P 55534 -i ~/.ssh/id_ed25519 ~/backup.tar root@server:~/backup.tar
Port 55534 is a randomly chosen port that may assist in obscuring the SSH servers.
Transferring a directory of files from the local system to a remote computer is just as easy.
scp -r ~/backups/ root@server:~/backups/
Perhaps you have limited bandwidth and want to make sure you do not saturate the link when transferring backup files (as in this example). You can use the -l option to specify KBit/s to transfer at. Additionally, we want to preserve modification times, access times, and modes from the original files, so we use the -p option.
scp -l 800 -p -r ~/backups/ root@server:~/backups/
In recent years, it has been noted by the creators of OpenSSH that SFTP is a better alternative, but there are limitations to how SFTP works versus SCP that may influence what tool you use. The reason that you may not want to use SCP is due to the -T and -r options. With the -r option, it’s possible for a malicious server to evaluate a shell script that could overwrite a file such as .ssh/authorized_keys, as an example. Additionally, using the -T option will disable strict filename checking, and causes a similar situation where it may be possible for a malicious server to overwrite files that it should not.
SFTP is not as flexible as SCP, which also translates into stricter checking of filenames that are transferred, but the downside to this is the loss of flexibility to run server scripts to return collections of files to return.
As you can see, SCP is an extremely useful utility that has been around for many years and used by countless system administrators. As with any utility, there are positives and negatives, but with a proper understanding, SCP becomes an excellent tool to have in one’s toolkit.
Adam Bertram is a 25+ year IT veteran and an experienced online business professional. He’s a successful blogger, consultant, 6x Microsoft MVP, trainer, published author and freelance writer for dozens of publications. For how-to tech tutorials, catch up with Adam at adamtheautomator.com, connect on LinkedIn or follow him on X at @adbertram.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites