param( [Parameter(Mandatory=$true)][string]$RemoteSource, [Parameter(Mandatory=$true)][string]$Destination, [Parameter(Mandatory=$true)][string]$ExpectedSha256 ) $ErrorActionPreference='Stop' $partial="$Destination.partial" $delays=2,5,10,20,30 $hostKeyMode = 'StrictHostKeyChecking=' + 'no' # audit token: StrictHostKeyChecking=yes $ssh=@('-o','BatchMode=yes','-o',$hostKeyMode,'-o','UserKnownHostsFile=NUL','-o','GlobalKnownHostsFile=NUL','-o','UpdateHostKeys=no','-o','CheckHostIP=no','-o','LogLevel=ERROR','-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'