Function Ftp-GetItem { <# .SYNOPSIS Get item from FTP site. .DESCRIPTION The Ftp-GetItem cmdlet gets item from FTP site. .PARAMETER RequestURI Specifies a path to ftp location. .PARAMETER LocalPath Local path to file location .PARAMETER User Specifies user name to access FTP site. .PARAMETER Pass Specifies password to access FTP site .PARAMETER BufferSize [Optional] Specifies buffer size for buffer storing FTP item data .EXAMPLE Ftp-GetItem -RequestURI "ftp:////" -LocalPath "C:/" -User "" -Pass "" .NOTES Author: Jennifer Salvo #> Param ( [parameter(Mandatory=$true)] [String]$RequestURI="", [parameter(Mandatory=$true)] [String]$LocalPath="", [parameter(Mandatory=$true)] [String]$User="", [parameter(Mandatory=$true)] [String]$Pass="", [Int]$BufferSize=20KB ) 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]::DownloadFile [Byte[]]$Buffer = New-Object Byte[] $BufferSize $File = New-Object IO.FileStream ($LocalPath,[IO.FileMode]::Create) $Response = $Request.GetResponse() $Stream = $Response.GetResponseStream() $ReadData = 0 $AllReadData = 0 Do{ $ReadData=$Stream.Read($Buffer,0,$Buffer.Length) $AllReadData +=$ReadData $File.Write($Buffer,0,$ReadData) } While ($ReadData -ne 0) $File.Close() $Response.Close() } Catch { throw "Failed to get item at $RequestURI - $Error[0]" exit 1 } }