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



I was able to resolve this issue myself. For future people, the issue was with the windows firewall. For some reason the server was not prompting to allow connections for this program as it was in Windows 7. I was able to resolve it by adding some code to create a firewall rule before the EnumerateRemoteFiles function is called.

EnumerateRemoteFiles hangs on Server 2012


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

##This is the code which hangs##
$sFTPFiles =
"/ftpFolder/", $Null,
([WinSCP.EnumerationOptions]::EnumerateDirectories -bor [WinSCP.EnumerationOptions]::AllDirectories))

$totalBytes = ($sFTPFiles | Measure-Object -Property Length -Sum).Sum

$MSIArray =
"/ftpFolder/", $Null,
([WinSCP.EnumerationOptions]::EnumerateDirectories -bor [WinSCP.EnumerationOptions]::AllDirectories)) |
Where-Object {$ -like '*.msi' -and $_.fullname -like "*/ftpFolder/*"}
$MSIArray = $MSIArray | Select -Unique

ForEach ($i in $MSIArray)
$sFTPMSIFile = $ -Replace ".msi"
[void] $selectBox.Items.Add($sFTPMSIFile)

Return $totalBytes