SeToY Geschrieben 2. März 2009 Geschrieben 2. März 2009 (bearbeitet) Hey, kann mir jemand erklären, warum er beim vierten knopf ne errormeldung rauswirft? "WebRequest.Create" ist rot unterkringelt, und Visual Studio 2005 sagt mir in der fehlerliste: ; expected Invalid expression therm ') ; expected using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Xml; using System.Net; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); Text = "Dateien in C:\\Temp"; this.WindowState = FormWindowState.Normal; } private void button1_Click(object sender, EventArgs e) { textBox1.Items.Clear(); List<string> files = this.GetFiles(@"C:\Temp", new List<string>()); string[] lines = new string[files.Count]; int i = 0; foreach (string file in files) { textBox1.Items.Add(file); i++; } } private List<string> GetFiles(string folderPath, List<string> fileList) { if (!Directory.Exists(folderPath)) return fileList; string[] dirs = Directory.GetDirectories(folderPath); foreach (string subDir in dirs) GetFiles(subDir, fileList); string[] files = Directory.GetFiles(folderPath, "*.config"); foreach (string file in files) if (!fileList.Contains(file)) fileList.Add(file); return fileList; } private void button2_Click(object sender, EventArgs e) { textBox1.Items.Clear(); } private void button3_Click(object sender, EventArgs e) { FileInfo file = new FileInfo(@"C:\Temp\export.txt"); StreamWriter writer = new StreamWriter(file.FullName); foreach (string line in textBox1.Items) { writer.WriteLine(line); } writer.Flush(); writer.Close(); } private void button4_Click(object sender, EventArgs e) { StreamReader reader = new StreamReader(textBox1.SelectedItem.ToString()); string file = textBox1.SelectedItem.ToString(); XmlDocument doc = new XmlDocument(); doc.LoadXml(reader.ReadToEnd()); reader.Close(); XmlNodeList nodelist = doc.SelectNodes("/configuration/loggingConfiguration/logFilters/add/categoryFilters/add"); foreach (XmlNode node in nodelist) { if (node.Attributes["name"].Value.ToLower() == "debug") { node.Attributes["name"].Value = "xxx"; } } StreamWriter writer = new StreamWriter(file+".new.config"); string[] xml = doc.InnerXml.Split('>'); //writer.WriteLine(xml[0] + ">"); foreach (string sfda in xml) { writer.WriteLine(sfda + ">"); } writer.Flush(); writer.Close(); } private void button5_Click(object sender, EventArgs e) { FtpWebRequest wr2 = FtpWebRequest)WebRequest.Create("ftp://81.201.103.97/"); // we need a proxy with credentials wr2.Proxy = new WebProxy("cristallo", 8080); wr2.Proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; // what do we want with the request? wr2.Method = WebRequestMethods.Ftp.ListDirectory; // we are firewalled, only PASV mode wr2.UsePassive = true; // get the response FtpWebResponse fwr = (FtpWebResponse)wr2.GetResponse(); // continue with getting the response stream, check the Status of the web response and that's it } } } [/php] danke und mfg SeToY :e@sy Edit: ich sehe auch gerade, dass der von mir verwendete code keinerlei benutzer oder passwörter abfragt.. das müsste ich aber auch machen Bearbeitet 2. März 2009 von SeToY Zitieren
Klotzkopp Geschrieben 2. März 2009 Geschrieben 2. März 2009 kann mir jemand erklären, warum er beim vierten knopf ne errormeldung rauswirft?Weil da eine schließende Klammer ohne zugehörige öffnende steht. Zitieren
SeToY Geschrieben 2. März 2009 Autor Geschrieben 2. März 2009 :upps danke ^^ Wie schaffe ich es jetzt, dass der mir den Verzeichnis-Inhalt auf dem verbundenen ftp-server anzeigt? im mom holt er es ja aus C:\Temp. Also brauche ich den inhalt vom ftp-server und gleichzeitig bei der verbindung eine abfrage für Username und Password Zitieren
SeToY Geschrieben 2. März 2009 Autor Geschrieben 2. März 2009 Sorry für doppelposten.. aber ich kann meine beiträge nur x minuten nach erstellunge editieren using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Xml; using System.Net; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); Text = "Dateien in C:\\Temp"; this.WindowState = FormWindowState.Normal; } private void button1_Click(object sender, EventArgs e) { textBox1.Items.Clear(); List<string> files = this.GetFiles(@"ftp://81.201.103.97/", new List<string>()); string[] lines = new string[files.Count]; int i = 0; foreach (string file in files) { textBox1.Items.Add(file); i++; } } private List<string> GetFiles(string folderPath, List<string> fileList) { if (!Directory.Exists(folderPath)) return fileList; string[] dirs = Directory.GetDirectories(folderPath); foreach (string subDir in dirs) GetFiles(subDir, fileList); string[] files = Directory.GetFiles(folderPath, "*.config"); foreach (string file in files) if (!fileList.Contains(file)) fileList.Add(file); return fileList; } private void button2_Click(object sender, EventArgs e) { textBox1.Items.Clear(); } private void button3_Click(object sender, EventArgs e) { FileInfo file = new FileInfo(@"C:\Temp\export.txt"); StreamWriter writer = new StreamWriter(file.FullName); foreach (string line in textBox1.Items) { writer.WriteLine(line); } writer.Flush(); writer.Close(); } private void button4_Click(object sender, EventArgs e) { StreamReader reader = new StreamReader(textBox1.SelectedItem.ToString()); string file = textBox1.SelectedItem.ToString(); XmlDocument doc = new XmlDocument(); doc.LoadXml(reader.ReadToEnd()); reader.Close(); XmlNodeList nodelist = doc.SelectNodes("/configuration/loggingConfiguration/logFilters/add/categoryFilters/add"); foreach (XmlNode node in nodelist) { if (node.Attributes["name"].Value.ToLower() == "debug") { node.Attributes["name"].Value = "xxx"; } } StreamWriter writer = new StreamWriter(file+".new.config"); string[] xml = doc.InnerXml.Split('>'); //writer.WriteLine(xml[0] + ">"); foreach (string sfda in xml) { writer.WriteLine(sfda + ">"); } writer.Flush(); writer.Close(); } private void button5_Click(object sender, EventArgs e) { FtpWebRequest wr2 = (FtpWebRequest)WebRequest.Create(new Uri ("ftp://81.201.103.97/")); wr2.credentials = new NetworkCredential("apptech", "@pptechGDH1;"); // we need a proxy with credentials wr2.Proxy = new WebProxy("cristallo", 8080); wr2.Proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; // what do we want with the request? wr2.Method = WebRequestMethods.Ftp.ListDirectory; // we are firewalled, only PASV mode wr2.UsePassive = true; // get the response FtpWebResponse fwr = (FtpWebResponse)wr2.GetResponse(); // continue with getting the response stream, check the Status of the web response and that's it wr2.Abort(); } } } [/php] bei "wr2.credentials" sagt er mir: 'System.Net.FtpWebRequest' does not contain a definition for 'credentials'. hilfe bitte :hells: Zitieren
Klotzkopp Geschrieben 2. März 2009 Geschrieben 2. März 2009 bei "wr2.credentials" sagt er mir: 'System.Net.FtpWebRequest' does not contain a definition for 'credentials'. Credentials mit großem C. Ein wenig mehr Sorgfalt bitte. Und auch ab und zu (z.B. vor dem Posten in einem Forum) in die Dokumentation gucken. FtpWebRequest Properties (System.Net) Zitieren
SeToY Geschrieben 5. März 2009 Autor Geschrieben 5. März 2009 danke dir bin soweit fertig, aber wie krieg ich es jetzt hin, dass ich mich beim proxy mit username und passwort anmelde? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Xml; using System.Net; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); Text = "web.config auslesen"; this.WindowState = FormWindowState.Normal; } private void button1_Click(object sender, EventArgs e) { textBox1.Items.Clear(); List<string> files = this.GetFiles(@"ftp://IP:DES:SERVERS/", new List<string>()); string[] lines = new string[files.Count]; int i = 0; foreach (string file in files) { textBox1.Items.Add(file); i++; } } private List<string> GetFiles(string folderPath, List<string> fileList) { if (!Directory.Exists(folderPath)) return fileList; string[] dirs = Directory.GetDirectories(folderPath); foreach (string subDir in dirs) GetFiles(subDir, fileList); string[] files = Directory.GetFiles(folderPath, "*.config"); foreach (string file in files) if (!fileList.Contains(file)) fileList.Add(file); return fileList; } private void button2_Click(object sender, EventArgs e) { textBox1.Items.Clear(); MessageBox.Show("Liste erfolgreich geleert!", "Erfolgt!"); } private void button3_Click(object sender, EventArgs e) { FileInfo file = new FileInfo(@"C:\Temp\export.txt"); StreamWriter writer = new StreamWriter(file.FullName); foreach (string line in textBox1.Items) { writer.WriteLine(line); } writer.Flush(); writer.Close(); MessageBox.Show("Liste erfolgreich nach C:\\Temp exportiert!", "Export erfolgreich!"); } private void button4_Click(object sender, EventArgs e) { StreamReader reader = new StreamReader(textBox1.SelectedItem.ToString()); string file = textBox1.SelectedItem.ToString(); XmlDocument doc = new XmlDocument(); doc.LoadXml(reader.ReadToEnd()); reader.Close(); XmlNodeList nodelist = doc.SelectNodes("/configuration/loggingConfiguration/logFilters/add/categoryFilters/add"); foreach (XmlNode node in nodelist) { if (node.Attributes["name"].Value.ToLower() == "debug") { node.Attributes["name"].Value = "xxx"; } } StreamWriter writer = new StreamWriter(file+".new.config"); string[] xml = doc.InnerXml.Split('>'); //writer.WriteLine(xml[0] + ">"); foreach (string sfda in xml) { writer.WriteLine(sfda + ">"); } writer.Flush(); writer.Close(); } private void button5_Click(object sender, EventArgs e) { FtpWebRequest wr2 = (FtpWebRequest)WebRequest.Create(new Uri ("ftp://IP:DES:SERVERS/")); wr2.Credentials = new NetworkCredential("DOMÄNE", "PASSWORT", "USER"); // we need a proxy with credentials wr2.Proxy = new WebProxy("PROXY_IP", 8080); wr2.Proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; // what do we want with the request? wr2.Method = WebRequestMethods.Ftp.ListDirectory; // we are firewalled, only PASV mode wr2.UsePassive = true; // get the response FtpWebResponse fwr = (FtpWebResponse)wr2.GetResponse(); // continue with getting the response stream, check the Status of the web response and that's it wr2.Abort(); MessageBox.Show("Verbindung hergestellt!", "Verbunden"); } } } [/php] Zitieren
Empfohlene Beiträge
Dein Kommentar
Du kannst jetzt schreiben und Dich später registrieren. Wenn Du ein Konto hast, melde Dich jetzt an, um unter Deinem Benutzernamen zu schreiben.