Disable Resume/Transfer settings during file transfer using PowerShell

Advertisement

sanjeev40084
Joined:
Posts:
1
Location:
nc

Disable Resume/Transfer settings during file transfer using PowerShell

We are using WinSCP .NET assembly from PowerShell to upload csv files in Everbridge SFTP server. The PowerShell code that we are using are almost same from WinSCP sample example: https://winscp.net/eng/docs/library_powershell#example
We just got notified that we need to update our process to upload the files to new modernized SFTP server: <invalid hyperlink removed by admin>
We updated our script to use the new SFTP server address, we then started getting error message similar to this:
Error: Exception calling Check with 0 argument(s): Transfer was successfully finished, but temporary transfer file Everbridge.csv.filepart could not be renamed to target file name Everbridge.csv. If the problem persists, you may try to turn off transfer resume support.
Permission denied.
Error code: 3
Error message from server (US-ASCII): Access denied
We were told we need to disable the resume/transfer settings so we updated code to this:
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
Now while executing the code we are getting this error message:
Error: Exception calling "Open" with "1" argument(s): "Method not found: 'Void System.Threading.EventWaitHandle..ctor(Boolean, System.Threading.EventResetMode, System.String, Boolean ByRef, System.Security.AccessControl.EventWaitHandleSecurity)'."
Any idea why this error message is being thrown or better yet, how do we disable resume/transfer setting so that our file gets uploaded without any error.

Thanks
Sanjeev

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,454
Location:
Prague, Czechia

Re: Disable Resume/Transfer settings during file transfer using PowerShell

You could not have started getting that error because you added the TransferOptions code. You must have changed something else. You would be getting that error, if you use PowerShell (Core) 6 or newer with WinSCP .NET assembly binary targeting .NET Framework. So either you changed the PowerShell version you are using or you have changed WinSCP .NET assembly.
Either use assembly binary targeting .NET Framework and Windows PowerShell 5.
Or assembly binary targeting .NET (Core) and PowerShell (Core) 6 (or newer).
See also https://winscp.net/eng/docs/library_powershell#install
and Method not found: ‘Void System.Threading.EventWaitHandle..ctor(…)’

Reply with quote

Guest

@martin this was the original code:
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
We only made 2 changes:
first change: updated the old SFTP address to new SFTP address
result: this gave us first error message about 'Access denied'

Second change: since we got the above error and we were told that was because of resume/transfer setting, we updated code like this:
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
result: this leaded to second error message about 'Method not found:'

We are currently using 5.17.7(Build 10640) version. Because the second error message says 'Method not found', just curious is ResumeSupport setting for TransferOptions available for this version?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,454
Location:
Prague, Czechia

Even the error message that you posted originally shows that you get the error at the Session.Open call. And that the method in question is EventWaitHandle..ctor internally used by the Session.Open. This has nothing to do with ResumeSupport. Your ResumeSupport code is most likely not even reached in your script (I assume you call Session.Open before you create the TransferOptions). Just try to rollback your script changes. You will most likely still get the same "Method not found" error.

So once again, make sure you use WinSCP .NET assembly binary compatible with your PowerShell/.NET version.

Reply with quote

Advertisement

You can post new topics in this forum