Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[C#] FTP-Verbindungen

Empfohlene Antworten

Veröffentlicht

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

  • Autor

: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

  • Autor

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:

  • Autor

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]

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.