I am trying to write a Powershell script that copies files from a Windows PC to a Linux box.
I am able to SSH into my remote Linux machine from a Powershell window using SSH keys (stored in %userprofile%/.ssh/
on the Windows machine. I can also run an SCP command from the terminal window copying files from the Windows machine to the Linux box.
However, the very same scp
command fails when run from a script (script.ps1
) with the following error:
ssh: Could not resolve hostname <hostname>: No such host is known.
lost connection
Anyone know why scp
cannot resolve the hostname when run as a script in Powershell, when it can from the terminal?
The scp command I am running looks like:
& C:\Windows\System32\OpenSSH\scp.exe -r 'bin/release/net7.0/linux-x64/publish' <user_name>@<comp_name>:/home/<user_name>/containers/net_ws/app
As an aside, I tried to ping the <comp_name>
from within the same script and it pings successfully, so there appears to be no issue resolving the comp_name
host within the powershell context.