Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


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

I was able to resolve this. Thanks!

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

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..."
               $fullDest = (Join-Path $destination $newName )
               $fileSourcePath = [WinSCP.RemotePath]::EscapeFileMask($newName)
               $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"
   Write-Host "Is the session open? " $session.Opened
   Get-Files $wildCard1
        Get-Files $wildCard2 "filename1.txt" -rename
   Get-Files $wildCard3 "filename2.txt" -rename
Write-Host "Error: $($_.Exception.Message)"
      exit 1

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?