Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 12th, 2010 | Syntax: None | Size: 0.81 KB | Hits: 69 | Expires: Never
Copy text to clipboard
  1. public static void DeleteDirectory(Ftp ftp, string remotePath)
  2. {
  3.     Console.WriteLine("Deleting directory: '{0}'",remotePath);
  4.  
  5.     // change the directory
  6.     ftp.ChangeDirectory(remotePath);
  7.  
  8.     // delete all files from the remotePath directory
  9.     FtpList files = ftp.GetList();
  10.     for (int i = 0; i < files.Count; i++)
  11.     {
  12.         if (files[i].IsFile)
  13.         {
  14.             Console.WriteLine("Deleting file: '{0}'", files[i].Name);
  15.  
  16.             ftp.DeleteFile(files[i].Name);
  17.         }
  18.     }
  19.  
  20.     // delete all subdirectories in the remotePath directory
  21.     for (int i = 0; i < files.Count; i++)
  22.     {
  23.         if (files[i].IsDirectory)
  24.             DeleteDirectory(ftp, files[i].Name);
  25.     }
  26.  
  27.     // delete this directory
  28.     ftp.ChangeDirectory("..");
  29.     ftp.RemoveDirectory(remotePath);
  30. }