0

I get more than one remote source not supported error on pscp if my script is written like this (no issues with plink) :

I want to retrieve files from multiple UNIX servers to local windows Could someone help me to verify my code?


#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]

}

However, if i run my script as below, i am able to retrieve files from multiple servers to one single local host.

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\

EDIT


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\

}
  • What do you mean by *"insert private key"*? Why are you doing `echo "n"`? Add `-v` to plink command line and show us the output that you get. – Martin Prikryl Mar 02 '20 at 06:40
  • @MartinPrikryl nevermind that, i could plink successfully into each server... however for now, the pscp is getting** more than one remote source is not supported**. However, I already specified the path to where i want to retireve the files .... – Anonymous01 Mar 02 '20 at 06:58

1 Answers1

0

I found some erros in your code: 1)Put this line

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

instead

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

2)You have only 2 elements in array your loop must be

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

3)You can use just this construction

$Dest_Path[$i]

instead

${Dest_Path[$i]}

Additional:

#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]

}

Try this fix

Vad
  • 693
  • 3
  • 13
  • hi yes i just realised that tq for pointing out. However now im getting More than one remote source is not supported on pscp even though i specified the absolute path.... And it keep llisting the whole option list of pscp as if to prompt me to enter an option for it – Anonymous01 Mar 02 '20 at 07:02
  • Try this `pscp -r $Server_IP[$i]:/cf/conf/backup/* $Dest_Path[$i]` if it can't more than one remote source, try add some pause in end. pscp – is utility for copying files in parallel to a number of hosts. prsync – is a utility for efficiently copying files to multiple hosts in parallel. pnuke – it helps to kills processes on multiple remote hosts in parallel. pslurp – it helps to copy files from multiple remote hosts to a central host in parallel. look what you want. – Vad Mar 02 '20 at 07:09
  • It seems pscp would not copy from multiple remote host....it seems that pslurp suits my current situation the most... however im getting pslurp is not recognised. Do i need to install extra package for pslurp? – Anonymous01 Mar 02 '20 at 07:36
  • It's inside package Parallel SSH Tools – Vad Mar 02 '20 at 07:43
  • It's inside package Parallel SSH Tools. If all your machines use windows you can do `Copy-item` cmdlet, it supports remote copy.[look this thread](https://stackoverflow.com/questions/10741609/copy-file-remotely-with-powershell) – Vad Mar 02 '20 at 07:50
  • my local is windows and my servers r FreeBSD... Want to retrieve files from server to windows. Running powershell script on local windows to retrieve it... so do i install this pssh on servers or windows? Sorry a bit confused, never work with this before.... – Anonymous01 Mar 02 '20 at 08:32
  • Tools as i know only for Unix*, then you must create share on servers and get files via `Copy-Item` cmdlet , look link above. or you can try this method [click here for another method](https://www.youtube.com/watch?v=0_IMGnsreuw) and one more [manual to install](https://mcpmag.com/articles/2018/07/19/transfer-files-via-scp-with-powershell.aspx) – Vad Mar 02 '20 at 08:39
  • before i tried your above suggestion.... could you help review my question again? i edited something on the main post As it seems this issue is only happens when im trying to run an array of ip on one loop session.... and not if i manually pscp multiple times. – Anonymous01 Mar 02 '20 at 08:56
  • Add in post info. But may be pscp need some delay , so then in your loop at end add `Start-Sleep -Seconds 5` – Vad Mar 02 '20 at 09:16
  • tq but it still showing the more than one remote issue .... apparently, my supervisor prefer to use pscp instead of pssh or pslurp due to certain reason. So if it is possible i would like to stick with pscp ... – Anonymous01 Mar 02 '20 at 09:23
  • pscp work with one server at time, you can't connect new server before you end download and connect to previous server. You can add check in scripts where you will check state of prosecc pscp, and start new loop when it close. – Vad Mar 02 '20 at 10:12
  • Bear with my ignorance... but how i perform the suppose check state and start new loop when it close? Technically speaking, the loop has indicated that pscp run n retrieve from one server, finishes the process, then only start a new loop for the other server. So it is not connecting with multiple servers concurrently. – Anonymous01 Mar 02 '20 at 10:24
  • i have no pscp on computer now and can't check, but i think when you run process "pscp" in loop, loop don't wait until job ends and send to process new parameters. – Vad Mar 02 '20 at 10:35
  • i have no pscp on computer now and can't check, but i think when you run process "pscp" in loop, loop don't wait until job ends and send to process new parameters. Try add in end loop something like this `while(Get-Process -Name nameofprocesspscp -ErrorAction SilentlyContinue){ Start-Sleep -Seconds 1}` – Vad Mar 02 '20 at 10:44
  • (Refer to my main post edit session) apparently if i use foreach it works but unable to work if i used for loop... I don't mind doing so but now i have no idea how to direct it to different destination for diff ip. – Anonymous01 Mar 03 '20 at 06:18