Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, July 12, 2011 5:56 PM
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
All replies (4)
Tuesday, July 12, 2011 7:12 PM âś…Answered | 3 votes
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()
Wednesday, October 2, 2013 2:49 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.
Friday, November 15, 2013 10:01 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:11 PM | 1 vote
There is a great powershell addon that allows you to use FTP. http://gallery.technet.microsoft.com/scriptcenter/PowerShell-FTP-Client-db6fe0cb
Just FYI.