0

如果我的脚本是这样编写的(plink 没有问题),我会在 pscp 上收到多个远程源不受支持的错误:

我想从多个 UNIX 服务器检索文件到本地窗口 有人可以帮我验证我的代码吗?


#Server Information:
$Server_IP=@("root@192.168.13.10","root@192.168.13.11")

$PPK_Path="C:\Users\me\Desktop\private-key.ppk"

#Local machine related information
$Dest_Path=@("C:\Users\me\Desktop\savehere01\","C:\Users\me\Desktop\savehere02\")


#Commands //Change with cautious

For ($i=0; $i -le 2; $i++) {

#Prompt computer to start plink.exe to insert private key and enable ssh
Echo "n" | plink -ssh -i $PPK_Path $Server_IP[$i]

#Prompt Powershell to run scp
pscp -r $Server_IP[$i]:/cf/conf/backup/* $Dest_Path[$i]

}

但是,如果我按如下方式运行我的脚本,我可以将文件从多台服务器检索到一台本地主机。

Echo "y" | plink -ssh -i C:\Users\me\Desktop\private-key.ppk root@192.168.13.32
pscp -pw testing -r root@192.168.13.10:/cf/conf/backup/* C:\Users\me\Desktop\savehere\

Echo "y" | plink -ssh -i C:\Users\me\Desktop\private-key.ppk root@192.168.13.11
pscp -pw testing -r root@192.168.13.11:/cf/conf/backup/* C:\Users\me\Desktop\savehere02\

编辑


foreach ($IP in $Server_IP){

#Prompt computer to start plink.exe to insert private key and enable ssh
Echo "y" | plink -ssh -i $PPK_Path $IP

#Prompt Powershell to run pscp
pscp -pw testing -r $IP":"/cf/conf/backup/* C:\Users\me\Desktop\savehere\

}
4

1 回答 1

0

我在你的代码中发现了一些错误:1)把这一行

$Server_Username[$i]+"@"+$Server_IP[$i]   

反而

${Server_Username[$i]}@${Server_IP[$i]}

2)您的数组中只有 2 个元素,您的循环必须是

($i=0; $i -lt 2; $i++) 

3)你可以使用这个结构

$Dest_Path[$i]

反而

${Dest_Path[$i]}

额外的:

#Commands //Change with cautious

For ($i=0; $i -lt 2; $i++) {

#Prompt computer to start plink.exe to insert private key and enable ssh
Echo "n" | plink -ssh -i $PPK_Path $Server_IP[$i]

#Prompt Powershell to run scp
pscp -r $Server_IP[$i]:/cf/conf/backup/* $Dest_Path[$i]

}

试试这个修复

于 2020-03-02T06:57:31.460 回答