0

I am struggling for a while with using variable with pscp command.

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

Output

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

When I try to specify hostname not using variable there isnt any issue with transferring of the file. However If I try to use variable $Server, I get an error "Local copy not supported" I thought it might be problem with variable itself but .\plink works without any issues

I have tried to use commas, escape @, full paths etc. nothing seems to be working. I cant use winscp.dll since in this specific case I need automatically accept host keys (which is insecure but really specific only to this case) - this is only provided by pscp.

Thanks a lot!

P.Mlejnek
  • 1
  • 2
  • WinSCP .NET assembly does support automatic accepting of host keys (use [`SessionOptions.GiveUpSecurityAndAcceptAnySshHostKey`](https://winscp.net/eng/docs/library_sessionoptions#giveupsecurityandacceptanysshhostkey)), exactly contrary to pscp, which does not. – Martin Prikryl Apr 12 '16 at 14:21

1 Answers1

0

I know this is quite old, but I stumbled across this issue as well. It turns out that you need to use the subexpression operator $() for the server variable like so:

$($Server)

So your commands would look like this:

.\pscp.exe -pw $password create_ssh $myUsername@$($Server):/home/$myUsername/create_ssh
.\plink.exe -pw $password $myUsername@$($Server) -C "uname -r"
jmgardn2
  • 981
  • 2
  • 8
  • 21