EnumerateRemoteFiles hangs on Server 2012

Advertisement

CyBear08
Joined:
Posts:
2

EnumerateRemoteFiles hangs on Server 2012

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

Reply with quote

Advertisement

CyBear08

Resolved

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.

Reply with quote

Advertisement

You can post new topics in this forum