Reputation: 85
I'm working with WinSCP in PowerShell to manage files in a FTP. In using the standard script given on the WinSCP website, I am getting this error:
Unable to find type [WinSCP.EnumerateOptions].
I am working in version 5.13 - fresh off the site.
$remotePath = "ftp://username:password@network:port/relevantfolder/"
$localPath = "C:/Users/me/localdir"
$mask = "*.*"
$files = EnumerateRemoteFiles(
$remotePath, $mask, [WinSCP.EnumerateOptions]::AllDirectories)
foreach ($fileInfo in $files)
{
Write-Host "Downloading $($fileInfo.FullName) ..."
$filePath = [WinSCP.RemotePath]::EscapeFileMask($fileInfo.FullName)
$session.GetFiles($filePath, $localPath + "\*").Check()
}
Upvotes: 1
Views: 407
Reputation: 202652
It's EnumerationOptions
, not EnumerateOptions
.
Session.EnumerateRemoteFiles
is a method, so you need to call it on Session
instance.
The path
argument of Session.EnumerateRemoteFiles
is a path, not an URL:
$remotePath = "/relevantfolder/"
Upvotes: 3
Reputation: 440421
To complement Martin Prikryl's effective solution:
Your problem came down to misremembering the type name, which in PowerShell doesn't surface until runtime.
You can mitigate the problem with PowerShell's tab completion, however:
[winscp.enumerate<tab> # NO completion, because no such type exists.
[winscp.enumeration<tab> # -> completion to [WinSCP.EnumerationOptions]
Note that completion even works without a namespace component (e.g., [enumerationo<tab>]
), but with short or common name prefixes there can be many matches to cycle through.
Conversely, if completion does not occur, the possible causes are:
The assembly implementing the target type isn't loaded into the session yet.
Add-Type -Path
/ Add-Type -AssemblyName
to load it or Import-Module
, if it comes with a module.You've mistyped the type name (prefix).
Upvotes: 2