Error: Unable to find type [WinSCP.EnumerationOptions].

Advertisement

rsford31
Joined:
Posts:
32

Error: Unable to find type [WinSCP.EnumerationOptions].

Hi,
I'm getting an error "Error: Unable to find type [WinSCP.EnumerationOptions]. Make sure that the assembly that contains this type is loaded."
There are two files that have a date and four digits. I can determine the date but the four digits change. I need to use a mask to locate the file names at the source, download and rename the files.
My code is as follows:
param ($CurrentDate, $Source, $Destination, $HostName, $UserName, $Password, $Protocol, $Port, $ModeValue, $Fingerprint, $FileName1, $FileName2, $FileName3)   
try {
   function Get-Files($wildCard, [switch]$rename, $newName) {
$fileInfos = $session.EnumerateRemoteFiles($path, $wildcard, [WinSCP.EnumerationOptions]::None)
               
         foreach ($fileInfo in $fileInfos)
         {
            Write-Host "File $($fileInfo.FullName) matches mask, searching contents..."
            if($rename){
               $fullDest = (Join-Path $destination $newName )
               $fileSourcePath = [WinSCP.RemotePath]::EscapeFileMask($newName)
            }else{
               $fullDest = (Join-Path $destination $fileInfo.FullName )
               $fileSourcePath = [WinSCP.RemotePath]::EscapeFileMask($fileInfo.FullName)
            }
            $transferResult = $session.GetFiles($fileSourcePath, $fullDest)
            if (!$transferResult.IsSuccess)
            {
               # Print error (but continue with other files)
               Write-Host $transferResult.Failures[0].Message
            }
            }
     }
   $date = [datetime]::ParseExact($CurrentDate,"yyyyMMdd",$null).AddDays(-1)
   $date = $date.ToString("yyyyMMdd") 
   $wildCard1 = "$($FileName1)$($date)*"
   $wildCard2 = "$($FileName2)$($date)*"
   $wildCard3 = "$($FileName3)$($date)*"
   Add-Type -Path "E:\Program Files\WinSCP 5.7.5\WinSCPnet.dll"
   $session = New-Object WinSCP.Session
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::$Protocol
        HostName = "$($HostName)"
        UserName = "$($UserName)"
      PortNumber = $Port
        Password = "$($Password)"
      SshHostKeyFingerprint = $FingerPrint 
    }
   $sessionOptions.AddRawSettings("ProxyMethod", 3)
   $sessionOptions.AddRawSettings("ProxyHost", "proxy")
   $session.SessionLogPath = "F:\WinscpLogs\log.txt"
   $session.Open($sessionOptions)
   Write-Host "Is the session open? " $session.Opened
   Get-Files $wildCard1 
        Get-Files $wildCard2 "filename1.txt" -rename
   Get-Files $wildCard3 "filename2.txt" -rename
   
}catch{
Write-Host "Error: $($_.Exception.Message)"
      exit 1
}finally{
      $session.Dispose()
}
I added
Write-Host "Is the session open? " $session.Opened
In the Get-Files function just to make sure that my $session object was accessible. It evaluated to "true". Any ideas?

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum