- <#
- .SYNOPSIS
- This script deletes a file from an FTP Server
- .DESCRIPTION
- This script is a rewrite of an MSDN Sample
- .NOTES
- File Name : Remove-FtpFile.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted tot:
- http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Remove-FtpFile.ps1
- Delete status: 250 DELE command successful.
- #>
- $ServerUri = New-Object System.Uri "ftp://www.reskit.net/powershell/foo.txt"
- # The serverUri parameter should use the ftp:// scheme.
- # It contains the name of the server file that is to be deleted.
- # Example: ftp://contoso.com/someFile.txt.
- if ($ServerUri.Scheme -ne [system.Uri]::UriSchemeFtp) {
- " Bad URI"; return
- }
- # Get the object used to communicate with the server.
- $request = [system.Net.FtpWebRequest]::Create($serverUri)
- $request.Method = [System.Net.WebRequestMethods+ftp]::Deletefile
- $Request.Credentials = New-Object System.Net.NetworkCredential "anonymous","tfl@psp.co.uk"
- $response = $request.GetResponse()
- "Delete status: {0}" -f $response.StatusDescription
- $response.Close();
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Monday, 4 October 2010
Remove-FtpFile.ps1
Subscribe to:
Post Comments (Atom)
2 comments:
The scripts you have provided for get ftp directory and delete file have reduced my time required to develop from weeks to hours.
Many thanks!
You have just saved me days of work trying to figure this stuff out.
Many thanks!
Post a Comment