Search code examples
.netpowershellftpwinscpwinscp-net

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() 
}

Solution

    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/"