2016-04-12 63 views
0

我在使用pscp命令时使用变量挣扎了一会儿。Powershell返回在pscp中使用变量时不支持本地副本

ForEach ($Server in $Servers) 
{ 
.\pscp.exe -pw $password create_ssh [email protected]$Server:/home/$myUsername/create_ssh 
.\plink.exe -pw $password [email protected]$Server -C "uname -r" 
} 

输出

Local to local copy not supported 
2.6.32-573.1.1.el6.x86_64 

当我尽量不使用可变心不是任何问题与文件的传送到指定的主机名。 但是如果我尝试使用变量$服务器,我得到一个错误“本地副本不支持” 我想这可能是与变量本身,但问题。\砰砰作品,未经我曾尝试使用逗号的任何问题

,逃脱@,完整路径等似乎没有任何工作。 我不能使用winscp.dll,因为在这种特殊情况下,我需要自动接受主机密钥(这是不安全的,但只针对这种情况) - 这只能由pscp提供。

非常感谢!

+0

的WinSCP .NET程序集不支持主机自动接受键(使用['SessionOptions.GiveUpSecurityAndAcceptAnySshHostKey'](https://winscp.net/eng/docs/library_sessionoptions#giveupsecurityandacceptanysshkeykey)),与pscp完全相反,它没有。 –

回答

0

我知道这是很老,但我碰到这个问题跌跌撞撞为好。事实证明,你需要使用的子表达式运算符$()服务器变量,像这样:

$($Server) 

所以你的命令应该是这样的:

.\pscp.exe -pw $password create_ssh [email protected]$($Server):/home/$myUsername/create_ssh 
.\plink.exe -pw $password [email protected]$($Server) -C "uname -r" 
+0

非常感谢! –

相关问题