Skip to content
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

New-WinSCPTransferOptions -ResumeSupport #9

Closed
OneLogicalMyth opened this Issue May 20, 2015 · 7 comments

Comments

Projects
None yet
2 participants
@OneLogicalMyth
Copy link

commented May 20, 2015

Hi there,

I noticed that the function didn't support resume support.
The script I have built needs it off, so have extended your function to support it.

I am new to Git hub so wasn't sure how I could contribute so please find below the working function with ResumeSupport included.

<#
.SYNOPSIS
    Sets options for file transfers.
.DESCRIPTION
    Sets available options for file transfers between the client and server.
.INPUTS
    None.
.OUTPUTS
    WinSCP.TransferOptions.
.PARAMETER FileMask
    http://winscp.net/eng/docs/file_mask
.PARAMETER FilePermissions
    Permissions to applied to a remote file (used for uploads only).
.PARAMETER PreserveTimeStamp
    Preserve timestamp (set last write time of destination file to that of source file). Defaults to true.
.PARAMETER TransferMode
    Possible values are TransferMode.Binary (default), TransferMode.Ascii and TransferMode.Automatic (based on file extension).
.EXAMPLE
    PS C:\> New-WinSCPTransferOptions -PreserveTimeStamp -TransferMode Binary

    PreserveTimestamp : True
    FilePermissions   : 
    TransferMode      : Binary
    FileMask          : 
    ResumeSupport     : default
.EXAMPLE
    PS C:\> New-WinSCPTransferOptions -FilePermissions (New-WinSCPFilePermissions -GroupExecute -OtherRead)

    PreserveTimestamp : True
    FilePermissions   : -----xr--
    TransferMode      : Binary
    FileMask          : 
    ResumeSupport     : default
.NOTES
.LINK
    http://dotps1.github.io/WinSCP
.LINK
    http://winscp.net/eng/docs/library_transferoptions
#>
Function New-WinSCPTransferOptions
{
    [CmdletBinding()]
    [OutputType([WinSCP.TransferOptions])]

    Param
    (
        [Parameter()]
        [ValidateScript({ -not ([String]::IsNullOrWhiteSpace($_)) })]
        [String]
        $FileMask,

        [Parameter()]
        [WinSCP.FilePermissions]
        $FilePermissions,

        [Parameter()]
        [Switch]
        $PreserveTimeStamp,

        [Parameter()]
        [WinSCP.TransferMode]
        $TransferMode,

        [Parameter()]
        [WinSCP.TransferResumeSupportState]
        $ResumeSupport
    )

    Begin
    {
        $transferOptions = New-Object -TypeName WinSCP.TransferOptions


        foreach ($key in $PSBoundParameters.Keys)
        {
            try
            {
                if($key -eq 'ResumeSupport'){
                    $transferOptions.ResumeSupport.State = $PSBoundParameters.$($key)
                }else{
                    $transferOptions.$($key) = $PSBoundParameters.$($key)
                }
            }
            catch [System.Exception]
            {
                throw $_
            }
        }
    }

    End
    {
        return $transferOptions
    }
}
@dotps1

This comment has been minimized.

Copy link
Owner

commented May 20, 2015

Great, i will get some .Tests for Pester to verify this functionality, and add it. Thanks!

@dotps1

This comment has been minimized.

Copy link
Owner

commented May 20, 2015

So, i have been looking into this, and i want to handle it a little bit different, basically, i think to match the rest of the module framework, the -ResumeSupport Parameter should accept an actual object of type WinSCP.TransferResumeSupport, which has two properties, State, and Threshold. That being said, there should be an additional Cmdlet called New-WinSCPTransferResumeSupport, that would create said object, and accept an object of type WinSCP.TransferResumeSupportState as the State Parameter. Would look like this:

New-WinSCPTransferOptions -ResumeSupport (New-WinSCPTransferResumeSupport -State On -Threshold 1000)

But when i tried to create this cmdlet, i found a potential bug. There is no Constructor defined for creating a WinSCP.TransferResumeSupport Object. I have submitted a post on the WinSCP Forums: http://winscp.net/forum/viewtopic.php?p=56882#56882. Once i get a response for this, i will determine on how i want to proceed. Very good call on this, thanks!

@OneLogicalMyth

This comment has been minimized.

Copy link
Author

commented May 20, 2015

Great news, glad I could help.
I agree an object is better, strange about the constructor missing, but not a big amount of work to add so hopefully a quick for them.

I am using my workaround for now as I need my script working. But will keep an eye on your bug report and this issue for progress.

@dotps1 dotps1 self-assigned this May 21, 2015

@dotps1 dotps1 added the enhancement label May 21, 2015

dotps1 added a commit that referenced this issue May 22, 2015

Added code for Issue #9 Work around
Added work-around for ResumeSupport parameter in the
New-WinSCPTransferOptions cmdlet.  Added New Cmdlets:
Add-WinSCPSessionOptionsRawSettings, Get-WinSCPFileChecksum.  Fixed
typos in comment based help.
@dotps1

This comment has been minimized.

Copy link
Owner

commented May 22, 2015

I don't think i will be getting that Constructor anytime soon, but i added similar code that you suggested into the source. It also has the Threshold parameter available as well.
I had some other functionality i wanted to get checked, i am still going to keep this issue 'Open' as i don't feel it is fixed as it truly should be, but if i cannot create a TransferResumeSupport Object, i cannot create that cmdlet.

Thanks again!

@OneLogicalMyth

This comment has been minimized.

Copy link
Author

commented May 23, 2015

Hey no worries. Glad I could help.

Was looking at your HP warranty module, noticed it was myself who started the thread on stack overflow. So useful that.

@dotps1

This comment has been minimized.

Copy link
Owner

commented Jan 8, 2016

Ok, so I'm going close this out, the WinSCP.TransferResumeSupport class is a Static class that is only Referenced by other classes, that is why there is no constructor for it. https://technet.microsoft.com/en-us/library/dd347632.aspx

thanks.

@dotps1 dotps1 closed this Jan 8, 2016

@dotps1

This comment has been minimized.

Copy link
Owner

commented Apr 16, 2017

I know is old, but the constructor for WinSCP.TransferResumeSupport is now exposed, so the State and Threshold Parameters are now moved to its own cmdlet: New-WinSCPTransferResumeSupport. This is currently in the Development branch if you want to check it out, otherwise it will be coming out with the next WinSCP version. which should be soon, they haven't release a new lib since February.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.