Zum Inhalt springen

[C#] FTP-Verbindungen


Empfohlene Beiträge

Geschrieben (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 von SeToY
Geschrieben

: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

Geschrieben

Sorry für doppelposten.. aber ich kann meine beiträge nur x minuten nach erstellunge editieren :rolleyes:


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:

Geschrieben

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]

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.

Gast
Auf dieses Thema antworten...

×   Du hast formatierten Text eingefügt.   Formatierung wiederherstellen

  Nur 75 Emojis sind erlaubt.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Editor leeren

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...