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
}