-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set-SFTPItem fails sometimes with ArgumentOutOfRangeException #556
Comments
You didn't show how exactly you call your script inside the I suspect that the error is there, because you do not use the index in a You can also try using my RSJob fork as it fixes a lot of original bugs, maybe yours is there :) |
Thank you for getting back to us. At line Simplified view: # Main script "Get or send SFTP file.ps1"
$actions | foreach-Object {
$invokeParams = @{
FilePath = '../Send to SFTP.ps1'
ArgumentList = ....
}
Start-Job @invokeParams
} # Child script "Send to SFTP.ps1"
$params = @{
ComputerName = $SftpComputerName
Credential = $sftpCredential
AcceptKey = $true
}
$sftpSession = New-SFTPSession @params
$sessionParams = @{
SessionId = $sftpSession.SessionID
}
$params = @{
Path = $tempFile.UploadFilePath
Destination = $SftpPath
}
Set-SFTPItem @sessionParams @params The code of the child script is fully isolated from all other code and is running in its own Can you tell me what you mean with not using the |
Sorry, I read -RSJob instead of -Job about index: I think you need full traceback, not just exception |
Thanks for getting back to us. We posted the full stack trace here. It's probably related to .NET 8 but we're not knowledgeable enough to understand this in detail. |
This seems to be an issue within PowerShell itself |
Description
We have a script that starts multiple jobs with
Start-Job
to upload or download files.Once in a while we have a file that is not uploaded and we receive a non terminating error like this:
The background process reported an error with the following message: Unhandled exception. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index').
What we did to find the issue
When adding
Start-Transcript
toSend to SFTP.ps1
, which is the script that is called within the job to upload the file, we get these verbose messages:This is the end of the transcript.
The issue
It does never reach the message
Write-Verbose 'File uploaded'
and the functionSet-SFTPItem
does not throw a terminating error although we use$ErrorActionPreference = 'Stop'
at the top of the script.The file is never uploaded and this happens only occasionally. We run 5 jobs simultaneously. We're a bit lost on why this is not going to the
Catch
clause or why the file is not uploaded after callingSet-SFTPItem
.Thank you for your help.
Possible root cause
It looks like
Set-SFTPItem
quits the entire script when something goes wrong like say the SFTP server aborting the connection during transfer.Extra info
With downloading files by using
Get-SFTPItem
we never have an issue.System info
The text was updated successfully, but these errors were encountered: