Hallo ich habe ein Problem und zwar wenn ich mein Programm starte dort dann auf den Download Button gehe bekomme ich folge Fehlermeldung:
Der Remote Server hat einen Fehler zurückgegeben (501) nicht implementiert
hier einmal der Code:
*Topic verschoben*
Der Remote Server hat einen Fehler zurückgegeben (501) nicht implementiert
hier einmal der Code:
C#-Quellcode
- void DownloadFtpDirectory(string url, string localPath)
- {
- try
- {
- HttpWebRequest listRequest = (HttpWebRequest)WebRequest.Create(url);
- listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
- List<string> lines = new List<string>();
- using (HttpWebResponse listResponse = (HttpWebResponse)listRequest.GetResponse())
- using (Stream listStream = listResponse.GetResponseStream())
- using (StreamReader listReader = new StreamReader(listStream))
- {
- while (!listReader.EndOfStream)
- {
- lines.Add(listReader.ReadLine());
- }
- }
- foreach (string line in lines)
- {
- string[] tokens =
- line.Split(new[] { ' ' }, 9, StringSplitOptions.RemoveEmptyEntries);
- string name = tokens[8];
- string permissions = tokens[0];
- string localFilePath = Path.Combine(localPath, name);
- string fileUrl = url + name;
- if (permissions[0] == 'd')
- {
- if (!Directory.Exists(localFilePath))
- {
- Directory.CreateDirectory(localFilePath);
- }
- DownloadFtpDirectory(fileUrl + "/", localFilePath);
- }
- else
- {
- HttpWebRequest downloadRequest = (HttpWebRequest)WebRequest.Create(fileUrl);
- downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile;
- using (HttpWebResponse downloadResponse =
- (HttpWebResponse)downloadRequest.GetResponse())
- using (Stream sourceStream = downloadResponse.GetResponseStream())
- using (Stream targetStream = File.Create(localFilePath))
- {
- byte[] buffer = new byte[10240];
- int read;
- while ((read = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
- {
- targetStream.Write(buffer, 0, read);
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
*Topic verschoben*
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcus Gräfe“ ()