public bool DeleteSubFolder(string folderName) { bool success = false; if (string.IsNullOrEmpty(folderName)) { throw new ArgumentException("The folder name is invalid for deleting subfolder"); } var folderList = new List <string>(); var fileList = new List <string>(); string message = string.Empty; if (IsSubFoderExisted(folderName)) { ListDirectory(out folderList, out fileList, folderName); if (folderList.Count > 0) { throw new ApplicationException(string.Format(@"The folder <{0}> contains sub folders and can't be deleted.", folderName)); } fileList.ForEach(file => { var uri = string.Format(@"{0}{1}{2}{1}{3}", FtpUri, PathSeparator, folderName, file); var ftpFile = new FTPFile(uri); ftpFile.DeleteFile(); }); var request = CreateRequest(WebRequestMethods.Ftp.RemoveDirectory, folderName); using (var response = request.GetResponse()) { success = true; response.Close(); } } else { message = @"Folder is not existed"; } return(success); }
public void DeleteFilNotExists() { var ftpFile = new FTPFile(string.Format(@"{0}/Foo.txt", _ftpUriConfigDetails.Uri.AbsoluteUri)); Assert.IsFalse(ftpFile.DeleteFile()); }