Function Ftp-DirectoryItemCount{ <# .SYNOPSIS Gets count of items on FTP site. .DESCRIPTION The Ftp-DirectoryItemCount cmdlet returns a count of all items on FTP site as an integer. .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-DirectoryItemCount -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 { $itemsOnFTP = New-Object System.Collections.ArrayList [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+' $itemsOnFTP = $itemsOnFTP + $Name [string]$Line = $Stream.ReadLine() } $Response.Close() } Catch { throw "Failed getting directory item count - $Error[0]" exit 1 } return $itemsOnFTP.Length }