英文:
Unknown hostname error when running SCP from Powershell script
问题
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:
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.
英文:
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.
答案1
得分: 0
Problem solved, thought full explanation is lacking.
问题已解决,但缺乏详细的解释。
I have solved the script issue by replacing the comp_name
with the ip address of the device.
我已通过将“comp_name”替换为设备的IP地址来解决脚本问题。
I'm still curious as to why scp is unable to resolve the ip address from the host name in this instance - i.e. when running as part of a script, rather than in the terminal, especially since other executables running in the same script context are able to find the host.
我仍然好奇为什么在这种情况下 scp 无法从主机名解析IP地址,即在脚本的一部分运行时,而不是在终端中运行,尤其是因为在相同脚本上下文中运行的其他可执行文件能够找到主机。
英文:
Problem solved, thought full explanation is lacking.
I have solved the script issue by replacing the comp_name
with the ip address of the device.
& C:\Windows\System32\OpenSSH\scp.exe -r 'bin/release/net7.0/linux-x64/publish'
<user_name>@<ip_address>:/home/<user_name>/containers/net_ws/app
I'm still curious as to why scp is unable to resolve the ip address from the host name in this instance - i.e. when running as part of a script, rather than in the terminal, especially since other executables running in the same script context are able to find the host.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论