- <#
- .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.
Showing posts with label System.Net.FtpWebRequest. Show all posts
Showing posts with label System.Net.FtpWebRequest. Show all posts
Monday, 4 October 2010
Remove-FtpFile.ps1
Sunday, 3 October 2010
Copy-FileToFtp.ps1
- <#
- .SYNOPSIS
- This script Uploads a text file to an FTP Server using PowerShell.
- .DESCRIPTION
- This script first creates an FTP 'web' request to upload a file. Then the
- source file is read from disk and written up to the FTP Server. A response
- is then displayed. This is a rewrite of an MSDN Sample.
- .NOTES
- File Name : Copy-FileToFtp.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/10/copy-filetoftpps1.html
- MSDN sample posted tot:
- http://msdn.microsoft.com/en-us/library/ms229715.aspx
- .EXAMPLE
- PSH [C:\foo]: .Copy-FileToFtp.ps1
- Upload File Complete, status 226
- 226 Transfer complete.
- #>
- # Get the object used to communicate with the server.
- $Request = [System.Net.FtpWebRequest]::Create("ftp://www.reskit.net/powershell/Greetings.Txt")
- $Request.Method = $Request.Method = [System.Net.WebRequestMethods+ftp]::UploadFile
- # This example assumes the FTP site uses anonymous logon.
- $Request.Credentials = New-Object System.Net.NetworkCredential "anonymous","tfl@psp.co.uk"
- # Copy the contents of the file to the request stream.
- $FileContents = [System.IO.File]::ReadAllBytes("C:\foo\scriptlib.zip")
- $Request.ContentLength = $fileContents.Length
- $RequestStream = $request.GetRequestStream()
- $RequestStream.Write($FileContents, 0, $FileContents.Length)
- $RequestStream.Close()
- $Response = $Request.GetResponse()
- "Upload File Complete, status {0}" -f $Response.StatusDescription
- $Response.Close()
Subscribe to:
Posts (Atom)