Function Ftp-AddItem { <# .SYNOPSIS Add new item to FTP site. .DESCRIPTION The Ftp-AddItem cmdlet adds new item to FTP site. .PARAMETER RequestURI Specifies a path to FTP location. .PARAMETER LocalPath Specifies local path .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-AddItem -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]::UploadFile $Response = $Request.GetRequestStream() [Byte[]]$Buffer = New-Object Byte[] $BufferSize $File = [IO.File]::OpenRead( (Convert-Path $LocalPath) ) $TotalData = (Get-Item $LocalPath).Length $ReadData = 0 $AllReadData = 0 Do { $ReadData = $File.Read($Buffer, 0, $Buffer.Length) $AllReadData += $ReadData $Response.Write($Buffer, 0, $ReadData); #Write-Progress -Activity "Upload File: $Path" -Status "Uploading:" -Percentcomplete ([int]($AllReadData/$TotalData * 100)) } While($ReadData -gt 0) $File.Close() $Response.Close() } Catch { throw "Failed to upload file $LocalPath - $Error[0]" exit 1 } }