I am trying to delete all the files in a folder via FTP. Below is the code I am trying.
Files is an array of strings each one if the name of a file in the folder with its extension.
When I run it I get an a reply of 206 but when I look in the folder all the files remain. I tried variations of the code below, including adding a delay, but still cannot delete the files. What have I missed?
foreach (var FileName2 in Files)
{
if (File.Exists(txtbx_save_backup_to.Text + "/" + FileName2))
{
FtpWebRequest Delrequest = (FtpWebRequest)WebRequest.Create(ftp_address + "/Temp/Backup/" + FileName2);
Delrequest.Credentials = new NetworkCredential(username, password);
Delrequest.Method = WebRequestMethods.Ftp.DeleteFile;
Task.Delay(1000);
using (FtpWebResponse response2 = (FtpWebResponse)request.GetResponse())
{
rchtxtbx_backup_comms.AppendText("Deleted File, status " + response2.StatusDescription + "\r");
rchtxtbx_backup_comms.ScrollToCaret();
}
}
}