Home » PowerShell » Copy Files From Windows to Linux using PowerShell

Copy Files From Windows to Linux using PowerShell

Use the SCP (Secure Copy) command is used to copy files from Windows to Linux, it uses the SSH protocol for encryption and authentication to transfer files from Windows to Linux and vice versa using a PowerShell terminal.

SCP command is also used to copy folders from one system to another system.

Copy File from Windows to Linux PowerShell
Copy File from Windows to Linux PowerShell

PSCP (PuTTY Secure Copy Protocol) command-line tool is also used to copy files from the Windows Computer to the Linux system.

In this article, we will discuss how to copy files from Windows to Linux using the SCP and pscp commands in the PowerShell terminal.

Use SCP to Copy Files from Windows to Linux using PowerShell

The SCP command securely transfers files between the system. To move files from Windows to Linux system, run the following command.

scp D:\ua.cer admin@shell-pc:/home/admin/
admin@shell-pc's password:

In the above PowerShell script, the scp command takes the file path and remote Linux system name to transfer the file to the destination /home/admin location in the Linux system

It asks you to enter the password of the Linux system, enter the password and hit enter.

After the successful transfer of the file from windows to the Linux system, it will display the output with file name, file size, and how much time it takes to copy a file and transfer status as given below:

ua.cer           | 1 kB |   1.5 kB/s | ETA: 00:00:00 | 100%

Use SCP to Copy Folder from Windows to Linux using PowerShell

Use the SCP command to copy the folder from Windows to the Linux system, run the following command.

scp -r D:\Certificates admin@shell-pc:/home/admin/
admin@shell-pc's password:

In the above PowerShell script, the scp command uses the switch -r to transfer the entire folder from Windows to the Linux system.

It asks for the password to authenticate the user before it copies the folder, upon successful authentication and authorization, it moves the folder from Windows to the Linux system.

The output of the above scp command that uses -r to move the folder is:

emr.cer                                                                               100% 2176    10.6KB/s   00:00
Exported_HMITest.cer                                                                  100%  752     3.7KB/s   00:00
Exported_HMITest.P7B                                                                  100%  752     3.6KB/s   00:00
Exported_HMITest.SST                                                                  100%  752     3.7KB/s   00:00
exported_iis.cer                                                                      100% 1088     5.3KB/s   00:00
exported_iiscert.pfx                                                                  100% 2669    12.9KB/s   00:00
exported_ua.cer                                                                       100% 1534     7.5KB/s   00:00
exported_ua.pem                                                                       100% 1534     7.5KB/s   00:00
iis.cer                                                                               100% 1138     5.6KB/s   00:00
iis.pem                                                                               100% 2182    10.7KB/s   00:00
iis1.pem                                                                              100% 2270    10.5KB/s   00:00
ua.cer                                                                                100% 1542     7.5KB/s   00:00

Use PSCP to Copy Files from Windows to Linux using PowerShell

The PSCP command-line tool securely transfers files and folders between the system. To copy files from Windows to a Linux system, run the following command.

pscp D:\exported_ua.cer admin@shell-pc:/home/admin/
admin@shell-pc's password:

In the above PowerShell script, the pscp command takes the file path and remote Linux system name to transfer the file to the destination /home/admin location in the Linux system

It asks you to enter the password of the Linux system, enter the password and hit enter.

After the successful transfer of the file from windows to the Linux system, it will display the output with file name, file size, and how much time it takes to copy a file and transfer status as given below:

exported_ua.cer           | 1 kB |   1.5 kB/s | ETA: 00:00:00 | 100%

Use PSCP to Copy Folder from Windows to Linux using PowerShell

Use the PSCP command to copy the folder from Windows to the Linux system, run the following command.

pscp -r D:\Expiry_Certificates admin@shell-pc:/home/admin/
admin@shell-pc's password:

In the above PowerShell script, the pscp command uses the switch -r to transfer the entire folder from Windows to the Linux system.

It asks for the password to authenticate the user before it copies the folder, upon successful authentication and authorization, it moves the folder from Windows to the Linux system.

The output of the above pscp command that uses -r to move the folder is:

Copy Folder from Windows to the Linux in PowerShell
Copy the Folder from Windows to the Linux in PowerShell

Cool Tip: How to copy files to other locations using PowerShell!

Conclusion

I hope the above article on how to use scp and pscp commands to copy the file from Windows to Linux system is helpful to you.

pscp command requires a pscp.exe file, you can download the pscp.exe executable file from the internet.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.