I wrote a PowerShell script to upload files using FTPto on my local computer.
After downloading the file, I want to delete it from the FTP server. I also wrote this code. But, unfortunately, it does not work.
Can someone help me point out what is wrong with my code? Any hints would be helpful ...
Here is my code
function Delete-File($Source,$Target,$UserName,$Password) { $ftprequest = [System.Net.FtpWebRequest]::create($Source) $ftprequest.Credentials = New-Object System.Net.NetworkCredential($UserName,$Password) if(Test-Path $Source) { "ABCDEF File exists on ftp server." $ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::DeleteFile $ftprequest.GetResponse() "ABCDEF File deleted." } } function Get-FTPFile ($Source,$Target,$UserName,$Password) {
Every time I execute this script, the only statement I get
ABCDEF file uploaded
or
ABCDEF file exists
I think Delete-File not executed at all ... any type of hint will be helpful.
source share