PoshCode Archive  Artifact Content

Artifact c1c4deba74e437a17b989eac4c392324accc27e5b278cd819692a2bcc7cb5f65:

  • File Remove-FTPFile.ps1 — part of check-in [6978f0df45] at 2018-06-10 13:20:59 on branch trunk — 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 (user: xandertrystin size: 1212)

# 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
	
}