# encoding: ascii
# api: powershell
# title: Remove-FTPFile
# description: Just a short function I wrote based on FTP Upload and download examples. Requires and absolute path to the file on the FTP server that you wish to remove i.e.  ftp://ftp.someserver.com/filetodelete.txt
# version: 0.1
# type: function
# author: xandertrystin
# license: CC0
# function: Remove-FTPFile
# x-poshcode-id: 3142
# x-archived: 2016-09-11T15:36:40
# x-published: 2012-01-04T14:47:00
#
# I have used it as part of script that looks for a trigger file at a given FTP server if found it downloads a zip file for processing then removes the trigger file from the site.
#
function Remove-FTPFile ($Source,$UserName,$Password)
{
  #Create FTP Web Request Object to handle connnection to the FTP Server
  $ftprequest = [System.Net.FtpWebRequest]::Create($Source)
  
  # set the request's network credentials for an authenticated connection  
	$ftprequest.Credentials = New-Object System.Net.NetworkCredential($username,$password)
	
	$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::DeleteFile
	
  # send the ftp request to the server  
	$ftpresponse = $ftprequest.GetResponse()  
	$ftpresponse
	
}
