- 1 year ago
CommandNotFoundException raised for scp.exe (OpenSSH) called by powershell
Comment
1 / 1
If you encounter a CommandNotFoundException
error for scp.exe
when it is called by PowerShell, it typically indicates that the scp
command is not recognized or not accessible in the current PowerShell session. Here are a few steps you can take to resolve the issue:
Check if OpenSSH is installed:
- Ensure that OpenSSH is installed on your Windows system. OpenSSH is not included by default on all versions of Windows, so you may need to install it separately.
- You can install OpenSSH on Windows 10 or Windows Server 2019 and later versions using the "Add or remove programs" or "Apps & features" settings in Windows.
Verify the installation directory:
- Confirm the installation directory of OpenSSH on your system. By default, OpenSSH binaries are located in
C:\Windows\System32\OpenSSH
. - If the
scp.exe
file is not located in this directory, it may be in a different location. In that case, you will need to provide the full path to thescp.exe
file when calling it in PowerShell.
- Confirm the installation directory of OpenSSH on your system. By default, OpenSSH binaries are located in
Add OpenSSH directory to PATH:
- If the
scp.exe
file is located in the OpenSSH installation directory (C:\Windows\System32\OpenSSH
), make sure that directory is added to the system's PATH environment variable. - To add the OpenSSH directory to PATH:
- Open the Control Panel on your Windows system.
- Go to "System and Security" > "System" > "Advanced system settings".
- In the System Properties dialog, click on the "Environment Variables" button.
- In the "System variables" section, locate the "Path" variable and click on "Edit".
- Add the OpenSSH installation directory (
C:\Windows\System32\OpenSSH
) to the list of paths. - Click "OK" to save the changes.
- Restart PowerShell to ensure the new PATH setting is applied.
- If the
Test the
scp
command:- Open a new PowerShell session and try running the
scp
command again. - If you provided the full path to the
scp.exe
file, ensure that the path is correct and accessible.
- Open a new PowerShell session and try running the
By following these steps, you should be able to resolve the CommandNotFoundException
error and successfully use scp
in PowerShell.