public virtual string CreateSite(FtpSite site) { // create folder if nessesary //if(!Directory.Exists(site.ContentPath)) // Directory.CreateDirectory(site.ContentPath); // create anonymous user account if required // blah blah blah // set account permissions // blah blah blah // check server bindings CheckFtpServerBindings(site.Bindings); // create FTP site ManagementObject objService = wmi.GetObject(String.Format("IIsFtpService='{0}'", FTP_SERVICE_ID)); ManagementBaseObject methodParams = objService.GetMethodParameters("CreateNewSite"); // create server bindings ManagementClass clsBinding = wmi.GetClass("ServerBinding"); ManagementObject[] objBinings = new ManagementObject[site.Bindings.Length]; for (int i = 0; i < objBinings.Length; i++) { objBinings[i] = clsBinding.CreateInstance(); objBinings[i]["Hostname"] = site.Bindings[i].Host; objBinings[i]["IP"] = site.Bindings[i].IP; objBinings[i]["Port"] = site.Bindings[i].Port; } methodParams["ServerBindings"] = objBinings; methodParams["ServerComment"] = site.Name; methodParams["PathOfRootVirtualDir"] = site.ContentPath; ManagementBaseObject objSite = objService.InvokeMethod("CreateNewSite", methodParams, new InvokeMethodOptions()); // get FTP settings string siteId = ((string)objSite["returnValue"]).Remove(0, "IIsFtpServer='".Length).Replace("'", ""); // update site properties ManagementObject objSettings = wmi.GetObject( String.Format("IIsFtpServerSetting='{0}'", siteId)); FillWmiObjectFromFtpSite(objSettings, site); // start FTP site ChangeSiteState(siteId, ServerState.Started); return(siteId); }
/// <summary> /// Supports managed resources disposal /// </summary> /// <returns></returns> public virtual string[] GetZones() { List <string> zones = new List <string>(); using (ManagementObjectCollection objZones = wmi.GetClass("MicrosoftDNS_Zone").GetInstances()) { foreach (ManagementObject objZone in objZones) { using (objZone) { if ((uint)objZone.Properties["ZoneType"].Value == 1) { zones.Add((string)objZone.Properties["Name"].Value); } } } } return(zones.ToArray()); }