Получение этой ошибки при загрузке сборки WinSCP .NET.
Ошибка: невозможно найти тип [WinSCP.EnumerationOptions]: убедитесь, что загружена сборка, содержащая этот тип.
Windows Server 2008. WinSCPnet.dll от 25 июня 2014 г. 1.1.6
Сценарий
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
}