How to use windows command prompt and powershell for SCP file transfer

Table of Contents

Introduction

SCP ( Secure Copy )  uses SSH tunnels to transfer the files from one machine to another . It is faster than TFTP transfer and also secure as it is encrypted using the SSH tunnels

Usually when trying to perform the SCP transfer from the Windows machine to a Linux or networking device we use the WinSCP GUI based tool . If you are not a fan of GUI based tools , we also have Cli alternatives to do the same SCP transfer. 

In the recent Windows releases , we have native SCP command support on both the Windows Command prompt and the Power Shell.

 In this Article we will cover examples on how to use the native scp cli command from the command prompt and the powershell to perform the SCP transfer 

Syntax for the SCP command usage 

Scp works similar to the copy (cp ) command syntax , where it copies from one path to another. Source and destination  path can be either local machine or remote machine. 

scp  < source path of the file >  < destination path of the file >

Command prompt scp command 

To open a command prompt , you can type “cmd” on the search toolbar on your windows machine and click the command prompt app to open a terminal 

Then to check whether the scp command is available on the Command prompt , we can just type scp on the terminal like the following example , it should prompt with the available options 

PS C:\Users\Discovering_systems>scp
usage: scp [-346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program] source ... target

File transfer from the Local windows machine to the remote linux or network devices using SCP 

In this example we are transferring the file “test-file.txt” from the local location “C:\Users\Discovering_systems” to a remote linux machine (192.168.44.154) path “/tmp” . Please note that we can also use the DNS names in place of the Ip address. 

PS C:\Users\Discovering_systems> scp test-file.txt  root@192.168.44.154:/tmp
root@192.168.44.154's password:
test-file.txt                                           100%    0     0.0KB/s   00:00

File transfer from the remote linux or network devices to  local windows machine directory path   using SCP

In this example we are transferring the file “config.txt” from the remote  linux machine (192.168.44.154 ) path “/tmp/” to local windows machine path “C:\Users\Discovering_systems\Documents” . Please note that we can also use the DNS names in place of the Ip address. 


PS C:\Users\Discovering_systems> scp  root@192.168.44.154:/tmp/config.txt  C:\Users\Discovering_systems\Documents
root@192.168.44.154's password:
config.txt                                                                            100%   29    28.1KB/s   00:00

Powershell SCP command

To open a Powershell terminal  , you can type “powershell” on the search toolbar on your windows machine and click the “Windows Powershell”  app to open a terminal. To validate whether the scp command is supported on the powershell , we can type the scp command and execute it. It should return the possible options available for usage. 


PS C:\Users\Discovering_systems> scp
usage: scp [-346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program] source ... target

File transfer from the Local windows machine to the remote linux or network devices using SCP 

In this example we are transferring the file “test-file.txt” from the local location “C:\Users\Discovering_systems” to a remote linux machine (192.168.44.154) path “/tmp” . We can also use the DNS names in place of the Ip address. Please note the power shell  local path differences when compared to the command prompt example. 

PS C:\Users\Discovering_systems> scp .\test-file.txt  root@192.168.44.154:/tmp
root@192.168.44.154's password:
test-file.txt                                                                         100%    0     0.0KB/s   00:00

File transfer from the remote linux or network devices to  local windows machine directory path   using SCP

In this example we are transferring the file “config.txt” from the remote  linux machine (192.168.44.154 ) path “/tmp/” to local windows machine path “C:\Users\Discovering_systems\Documents” . Please note that we can also use the DNS names in place of the Ip address. 

PS C:\Users\Discovering_systems> scp  root@192.168.44.154:/tmp/config.txt  C:\Users\Discovering_systems\Documents
root@192.168.44.154's password:
config.txt                                                     100%   29    28.3KB/s   00:00

Conclusion

In this article we learned how to use SCP command for file transfer  natively from the Windows  command prompt and powershell. 

If you are interested in more articles like this , please check our series of Windows and linux networking articles in the link below 

https://discoveringsystems.com/category/linux-networking/

Leave a Comment

Your email address will not be published. Required fields are marked *