Function Ftp-DirectoryItemSize { <# .SYNOPSIS Gets total size (in KB) of all items on FTP site. .DESCRIPTION The Ftp-DirectoryItemSize cmdlet returns total size (in KB) of 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-DirectoryItemSize -RequestURI "ftp:////" -User "" -Pass "" .NOTES Author: Jennifer Salvo #> Param ( [parameter(Mandatory=$true)] $requestURI="", [parameter(Mandatory=$true)] [String]$User="", [parameter(Mandatory=$true)] [String]$Pass="" ) Try { $sizeOnFTP = 0 [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+' $sizeOnFTP = $sizeOnFTP + $Size [string]$Line = $Stream.ReadLine() } $Response.Close() } Catch { throw "Failed getting directory item size - $Error[0]" exit 1 } return ($sizeOnFTP / 1024) }