Hi,
ich habe einen FTP Server unter Windows Server 2008 R2 laufen. Das ganze ist im Server Manager unter IIS konfigurierbar. Mein Homeserver ist so eingestellt, dass er sich nach 10 min in den Standby herunterfährt (über Delphi gesteuert).
Leider fährt er sich auch herunter, wenn eine FTP Sitzung gerade aktiv ist, deshalb muss man sich immer neu verbinden.
Im Server Manager kann man die aktuellen FTP Sitzungen sehen, kann man diese auch per Delphi abfragen?
Ich benutze Delphi 7.
LG Dulla
---
Moderiert von
Narses: Beiträge zusammengefasst---
Ich habe eine Möglichkeit gefunden mittels C++ oder Javascript die FTP Sessions zu erfragen, kann man das ganze damit auch in Delphi umsetzen?
C#
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65:
| using System; using System; using System.Text; using Microsoft.Web.Administration;
internal static class Sample { private static void Main() { using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetApplicationHostConfiguration(); ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites"); ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"ftp.example.com"); if (siteElement == null) throw new InvalidOperationException("Element not found!");
ConfigurationElement ftpServerElement = siteElement.GetChildElement("ftpServer"); ConfigurationElementCollection sessionsElement = ftpServerElement.GetChildElement("sessions").GetCollection();
Console.WriteLine(String.Format("Active Sessions: {0}", sessionsElement.Count));
foreach (ConfigurationElement sessionElement in sessionsElement) { Console.WriteLine(String.Format("\tSession ID: {0}", sessionElement.Attributes["sessionId"].Value.ToString())); Console.WriteLine(String.Format("\t\tUser Name: {0}", sessionElement.Attributes["userName"].Value.ToString())); Console.WriteLine(String.Format("\t\tPrevious Command: {0}", sessionElement.Attributes["previousCommand"].Value.ToString())); } } }
private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues) { foreach (ConfigurationElement element in collection) { if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase)) { bool matches = true; for (int i = 0; i < keyValues.Length; i += 2) { object o = element.GetAttributeValue(keyValues[i]); string value = null; if (o != null) { value = o.ToString(); } if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase)) { matches = false; break; } } if (matches) { return element; } } } return null; } } |
JavaScript
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44:
| var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager'); adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"; var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");
var sitesCollection = sitesSection.Collection; var siteElementPos = FindElement(sitesCollection, "site", ["name", "ftp.example.com"]); if (siteElementPos == -1) throw "Element not found!"; var siteElement = sitesCollection.Item(siteElementPos);
var ftpServerElement = siteElement.ChildElements.Item("ftpServer"); var sessionsElement = ftpServerElement.ChildElements.Item("sessions").Collection;
WScript.Echo("Active Sessions: " + sessionsElement.Count);
for (var i = 0; i < sessionsElement.Count; i++) { var sessionElement = sessionsElement.Item(i); WScript.Echo("\tSession ID: " + sessionElement.GetPropertyByName("sessionId").Value); WScript.Echo("\t\tUser Name: " + sessionElement.GetPropertyByName("userName").Value); WScript.Echo("\t\tPrevious Command: " + sessionElement.GetPropertyByName("previousCommand").Value); }
function FindElement(collection, elementTagName, valuesToMatch) { for (var i = 0; i < collection.Count; i++) { var element = collection.Item(i); if (element.Name == elementTagName) { var matches = true; for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) { var property = element.GetPropertyByName(valuesToMatch[iVal]); var value = property.Value; if (value != null) { value = value.toString(); } if (value != valuesToMatch[iVal + 1]) { matches = false; break; } } if (matches) { return i; } } } return -1; } |