Answered by:
Remove Files on FTP Site with Powershell

Question
-
Good Day
I need to remove a File (ftp://11.19.2.10/FishFood_Price_20110712.csv) an FTP Site ftp://11.19.2.10, my username is DarkJoker and password is $hortN@m3, because my server has powershell fully setup and we will be moving it to a new VM enviroment I can not install any new programs, how can i use powershell to delete files on an FTP Site of which i have full access to.
Regards
Nishol
Tuesday, July 12, 2011 5:56 PM
Answers
-
Hi,
Try use FtpWebRequest class:
$sourceuri = "ftp://<user>@<ftpserver>/<file>" $ftprequest = [System.Net.FtpWebRequest]::create($sourceuri) $ftprequest.Credentials = New-Object System.Net.NetworkCredential(<User>,<pass>) $ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::DeleteFile $ftprequest.GetResponse()
- Proposed as answer by Marco Shaw Wednesday, July 13, 2011 12:11 AM
- Marked as answer by Marco Shaw Thursday, July 14, 2011 3:43 PM
Tuesday, July 12, 2011 7:12 PM
All replies
-
Hi,
Try use FtpWebRequest class:
$sourceuri = "ftp://<user>@<ftpserver>/<file>" $ftprequest = [System.Net.FtpWebRequest]::create($sourceuri) $ftprequest.Credentials = New-Object System.Net.NetworkCredential(<User>,<pass>) $ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::DeleteFile $ftprequest.GetResponse()
- Proposed as answer by Marco Shaw Wednesday, July 13, 2011 12:11 AM
- Marked as answer by Marco Shaw Thursday, July 14, 2011 3:43 PM
Tuesday, July 12, 2011 7:12 PM -
Hello.
Very nice script for deleting file, which name is alredy known.
How can it be modified to delete all files which older than 5 days?
I need something like this but working with ftp:
FORFILES /P C:\1 /D -5 /M *.* /C "cmd /c del @path"
Thanks for help in advanced.
Wednesday, October 2, 2013 2:49 PM -
Just use powershell:
$Now = Get-Date
$DayTime = "$($Now.ToShortDateString()) $($Now.ToShortTimeString())"
$LastWrite = $Now.AddHours(-24)
$Files = Get-ChildItem $TargetDirectory -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}
foreach ($File in $Files)
{
//whatever}
}
Friday, November 15, 2013 10:01 PM -
There is a great powershell addon that allows you to use FTP. http://gallery.technet.microsoft.com/scriptcenter/PowerShell-FTP-Client-db6fe0cb
Friday, November 15, 2013 10:11 PM