Error: Unable to find type [WinSCP.EnumerationOptions].
I was able to resolve this. Thanks!
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()
}
Write-Host "Is the session open? " $session.Opened