1

Getting this error when loading WinSCP .NET assembly.

Error: Unable to find type [WinSCP.EnumerationOptions]: make sure that the assembly containing this type is loaded.

Windows Server 2008. WinSCPnet.dll dated 25th ‎June ‎2014 1.1.6

Script

param (
    $remotePath = "/Temp/AAA/BBBB/",
    $wildcard = "*.BAK"
     )

try
{
    # Load WinSCP .NET assembly
    Add-Type -Path "D:\XXX\XXX\WinSCPnet.dll"

    #Add-type -assemblyName "System.ServiceProcess"   

    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = "AAAA"
        UserName = "BBBB"
        Password = "CCCC"
    }

    $session = New-Object WinSCP.Session

    try
    {
        # Connect
        $session.Open($sessionOptions)


        # Get list of matching files in the directory
        $files =
            $session.EnumerateRemoteFiles(
                $remotePath, $wildcard, [WinSCP.EnumerationOptions]::None)

        # Any file matched?
        if ($files.Count -gt 0)
        {
            foreach ($fileInfo in $files)
            {
                Write-Host ("$($fileInfo.Name) with size $($fileInfo.Length), " +
                    "permissions $($fileInfo.FilePermissions) and " +
                    "last modification at $($fileInfo.LastWriteTime)")
            }
        }
        else
        {
            Write-Host "No files matching $wildcard found"
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }

    exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}

1 Answer 1

1

Method Session.EnumerateRemoteFiles (including EnumerationOptions type) was added to WinSCP .NET assembly in version 5.8.

What was in December 2015. You are using version 5.5.4. You need to upgrade.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok Thanks that makes sense. Will the new upgrade have any impact on the old working scripts? is it backward compatible. Rgs
Incompatible changes are very rare. They are documented here: winscp.net/eng/docs/incompatible_changes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.