PoshCode Archive  Artifact [c2d610ee64]

Artifact c2d610ee640931baea153ad917a0780cb0a42a1e990a64b0d9a76b437b15bdc5:

  • File Remove-FTPFile.ps1 — part of check-in [7dc1ce171a] at 2018-06-10 13:26:05 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: 3463
# x-archived: 2016-06-06T19:14:38
# x-published: 2013-06-20T04:05: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
	
}