param( [Parameter(Mandatory=$true)][string]$RemoteSource, [Parameter(Mandatory=$true)][string]$Destination, [Parameter(Mandatory=$true)][string]$ExpectedSha256, [string]$KnownHosts = 'C:\temp\prod2u-thermal\receipts\known_hosts' ) $ErrorActionPreference='Stop' if(-not (Test-Path -LiteralPath $KnownHosts -PathType Leaf)){throw 'REMOTE_HOST_KEY_CONFIRMATION_REQUIRED'} $partial="$Destination.partial" $delays=2,5,10,20,30 $ssh=@('-o','BatchMode=yes','-o','StrictHostKeyChecking=yes','-o',"UserKnownHostsFile=$KnownHosts",'-o','ConnectTimeout=10','-o','ServerAliveInterval=15','-o','ServerAliveCountMax=4') for($i=0;$i -lt $delays.Count;$i++){ $savedPreference=$ErrorActionPreference $ErrorActionPreference='Continue' & scp @ssh "edk2-uefi-lab:$RemoteSource" $partial $exitCode=$LASTEXITCODE $ErrorActionPreference=$savedPreference if($exitCode -eq 0){ $sha=(Get-FileHash -Algorithm SHA256 -LiteralPath $partial).Hash.ToLowerInvariant() if($sha -eq $ExpectedSha256.ToLowerInvariant()){ Move-Item -LiteralPath $partial -Destination $Destination -Force Write-Output "TRANSFER_PASS sha256=$sha local=$Destination" exit 0 } } if($i -lt $delays.Count-1){Start-Sleep -Seconds $delays[$i]} } throw 'REMOTE_NETWORK_UNSTABLE'