C# .NET - How to delete the FTP folder in run time using C# code

Asked By guna guna on 24-Dec-09 05:19 AM
Hi,

 Can anyone tried to delete FTP folder in run time ..

Ensure that you have logged in and

[)ia6l0 iii replied to guna guna on 24-Dec-09 05:39 AM
use the RemoveDirectory method of the WebRequest methods.  

The sample snippet does what you need.

FtpWebRequest myFtpWebRequest = null;
myFtpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(folderPath));
myFtpWebRequest.Method = WebRequestMethods.Ftp.RemoveDirectory;
myFtpWebRequest.UseBinary = true;
myFtpWebRequest.Credentials = new NetworkCredential(userid, password);
FtpWebResponse response = (FtpWebResponse)myFtpWebRequest.GetResponse();
....

Needless to say, you need to provide the stuff marked.

Note that this method is only available in .Net framework versions 2.0 and above. The documentation can be found http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp.removedirectory(VS.80).aspx.

Re

Huggy Bear replied to guna guna on 24-Dec-09 05:49 AM
In addition to Diablo's reply, make sure the FTP user credentials you have used in your application has the delete permission on the FTP server, else it will throw an access denied error.

Re - delete the FTP folder in run time using C# code

DL M replied to guna guna on 24-Dec-09 06:07 AM
show this link about FTP in C#

http://www.example-code.com/csharp/ftp.asp
Thanks "Huggy Bear"
[)ia6l0 iii replied to Huggy Bear on 24-Dec-09 10:00 AM
I revisited this thread to add exactly what you mentioned.  Glad you caught it early.
Kalit Sikka replied to [)ia6l0 iii on 08-Oct-10 04:45 AM
how to delete folder, if it has file in it or folder with multiple files.

How to run recursive loop to delete contents of folder and folder itself