Hello!
So I'm using the WinSCP .net assembly to download files from a PowerShell application. I'm trying to utilize the beta version 5.8.3, which I downloaded about two months ago. I'm utilizing that beta version because it contains the EnumerateRemoteFiles function which I can use to get the total size of files to be downloaded. That total size is then used as a compare value in a progress bar which allows me to know the percentage of data downloaded, and when the download is completed. My code works perfectly fine in Windows 7, where I wrote it, but recently I tested the application in Windows Server 2012 and the code consistently hangs at the first EnumerateRemoteFiles function and cannot continue. I'm wondering if this is an issue with WinSCP, I believe the code is fine since it works in Windows 7, or if it this is a server setup issue which I need to account for. Below is the code I'm using which hangs.
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::ftp
HostName = $server
UserName = $username
Password = $password
PortNumber = "990"
ftpmode = "Active"
ftpsecure = "Implicit"
}
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)
##This is the code which hangs##
$sFTPFiles =
$session.EnumerateRemoteFiles(
"/ftpFolder/", $Null,
([WinSCP.EnumerationOptions]::EnumerateDirectories -bor [WinSCP.EnumerationOptions]::AllDirectories))
################################
$totalBytes = ($sFTPFiles | Measure-Object -Property Length -Sum).Sum
$MSIArray =
$session.EnumerateRemoteFiles(
"/ftpFolder/", $Null,
([WinSCP.EnumerationOptions]::EnumerateDirectories -bor [WinSCP.EnumerationOptions]::AllDirectories)) |
Where-Object {$_.name -like '*.msi' -and $_.fullname -like "*/ftpFolder/*"}
$MSIArray = $MSIArray | Select -Unique
ForEach ($i in $MSIArray)
{
$sFTPMSIFile = $i.name -Replace ".msi"
[void] $selectBox.Items.Add($sFTPMSIFile)
}
$session.Dispose()
Return $totalBytes