加载WinSCP .NET程序集时出现此错误。
错误:无法找到类型[WinSCP.EnumerationOptions]:确保已加载包含此类型的程序集。
Windows Server 2008. WinSCPnet.dll日期为2014年6月25日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
}
答案 0 :(得分:1)
Method Session.EnumerateRemoteFiles
(包括EnumerationOptions
类型)为added to WinSCP .NET assembly in version 5.8。
2015年12月的内容。您使用的是5.5.4版。你需要升级。