Friends,
In my last post, we saw how can we retrieve the list of all files & folders from a FTP server using C#. In this post, we will see how can we delete a file from FTP server using C# from within your Console or Windows Forms Application.
Here's the code:
- private string DeleteFile(string fileName)
- {
- FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.server.com/" + fileName);
- request.Method = WebRequestMethods.Ftp.DeleteFile;
- request.Credentials = new NetworkCredential("username", "password");
- using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
- {
- return response.StatusDescription;
- }
- }
Hope you like this post! Keep learning and sharing! Cheers!


Irving GutiérrezPosted Apr 28, 2022, 9:18 AM EDT
Nice, thanks!
Rami IssaPosted Sep 27, 2020, 9:28 PM EDT
Small article and direct to the point,thank you
Mazingaizo KunamaPosted Aug 14, 2019, 4:47 AM EDT
Hi Nitesh am bbatlling to delete folders from ftp can you help
Ibrahim RashidPosted Jan 27, 2015, 10:30 PM EST
Nice article..small one with big impact.
Vithal WadjeTOP 100Posted Jan 27, 2015, 5:32 AM EST
nice to learn sir,thanks for sharing