Function Ftp-ItemsToProcess { <# .SYNOPSIS Get list of items on FTP site. .DESCRIPTION The Ftp-ItemsToProcess cmdlet returns list of files on FTP server as an array. .PARAMETER RequestURI Specifies a path to ftp location. .PARAMETER User Specifies user name to access FTP site. .PARAMETER Pass Specifies password to access FTP site .EXAMPLE Ftp-ItemsToProcess -RequestURI "ftp:///" -User "" -Pass "" .NOTES Author: Jennifer Salvo #> Param ( [parameter(Mandatory=$true)] [String]$RequestURI="", [parameter(Mandatory=$true)] [String]$User="", [parameter(Mandatory=$true)] [String]$Pass="" ) Try { [System.Net.FtpWebRequest]$Request = [System.Net.WebRequest]::Create($RequestURI) $Request.Credentials = New-Object System.Net.NetworkCredential($User,$Pass) $Request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectoryDetails $Response = $Request.GetResponse() [System.IO.StreamReader]$Stream = $Response.GetResponseStream() Try{ [string]$Line = $Stream.ReadLine() } Catch{ $Line = $null } while ($Line) { [string]$Date,[string]$Time,[string]$Size,[string]$Name = $Line -split '\s+' $itemsToProcess = $itemsToProcess + $Name [string]$Line = $Stream.ReadLine() } $Response.Close() } Catch { throw "Failed while retrieving items to process - $Error[0]" exit 1 } return $itemsToProcess }