Search code examples
powershellsftpwinscpwinscp-net

WinSCP Disable ResumeSupport in PowerShell


I am using WinSCP to write to connect a SQL Server to an SFTP server. I am trying to write a file to an SFTP server where I only have write access, not modify. I am having a problem because I get back

Cannot create remote file '/xxx.filepart'.

The documentation suggests this is because I do not have modify access to the target directory. I did this WinSCP -> Preferences -> Endurance -> Disable
I checked the winscp.ini file and ResumeSupport is 2 (I believe this means disabled). I ran "echo $transferOptions.ResumeSupport" and it says that it is in a default state.

I have checked this documentation:
https://winscp.net/eng/docs/ui_pref_resume
https://winscp.net/eng/docs/library_transferoptions#resumesupport

However, I don't see a PowerShell example, just C#.

I have tried various permutations of $transferOptions.ResumeSupport.State = Off, $transferOptions.ResumeSupport.Off, and whatnot. One of these says that it's read-only.

I know $transferOptions is a variable here but it comes from the default script. The object determines transfer options $transferOptions = New-Object WinSCP.TransferOptions

Thanks in advance for help

edit: The overall problem is I only have write access to the server, but not modify. I am getting a new error: "Cannot overwrite remote file '/xxx'.$$. It looks like the dollar signs are some sort of temp file that it's trying to create. Is there a way to disable whatever setting is causing this?


Solution

  • Syntax for using an enumeration in PowerShell is described in the article Using WinSCP .NET assembly from PowerShell.

    Enumeration values are accessed using static field syntax [Namespace.Type]::Member, for example [WinSCP.Protocol]::Sftp.


    You can find a PowerShell example for TransferResumeSupport.State in Converting to .NET assembly section of get and put command documentation:

    $transferOptions = New-Object WinSCP.TransferOptions
    $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
    $session.GetFiles(..., ..., $False, $transferOptions).Check()
    

    WinSCP GUI can also generate a code template (including TransferOptions and TransferResumeSupportState code) for you.