James Reade
James Reade

Reputation: 85

Unable to find type [WinSCP.EnumerateOptions]

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].

enter image description here

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

Answers (2)

Martin Prikryl
Martin Prikryl

Reputation: 202652

  1. It's EnumerationOptions, not EnumerateOptions.

  2. Session.EnumerateRemoteFiles is a method, so you need to call it on Session instance.

  3. The path argument of Session.EnumerateRemoteFiles is a path, not an URL:

    $remotePath = "/relevantfolder/"
    

Upvotes: 3

mklement0
mklement0

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.

    • Use 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).

    • Experiment with variants using tab completion or consult the docs.

Upvotes: 2

Related Questions