Jump to content

ChristianErdtmann

Members
  • Gesamte Inhalte

    6
  • Registriert seit

  • Letzter Besuch

Letzte Besucher des Profils

Der "Letzte Profil-Besucher"-Block ist deaktiviert und wird anderen Benutzern nicht angezeit.

Fortschritt von ChristianErdtmann

Apprentice

Apprentice (3/14)

  • Erste Antwort
  • Erster eigener Beitrag

Neueste Abzeichen

0

Reputation in der Community

  1. Schwer misszuverstehen für was man hier postet wenn man beim thema auswählen muss wofür o0 ? Und wie gesagt dachte mit englisch erreich ich mehr.
  2. Hey, ich habe einen Windows Server 2019 gekauft und versuche, das folgende C#-Programm auszuführen. Auf meinem lokalen PC funktioniert alles einwandfrei, es verbindet sich und lädt alle Daten von meinem FTP. Aber auf meinem lokalen PC verwende ich reqFTP.UsePassive = false; Auf dem Windows - Server ist die Anfrage immer abgelaufen, wenn ich versuche, reqFTP.UsePassive = false zu verwenden; also habe ich reqFTP.UsePassive = true verwendet; Dies war der erste Schritt.Das Programm startet nun connect und kopiert den ersten Ordner meiner Verzeichnisse. Aber das ist alles. Es las alle Ordner und las den Inhalt des ersten Ordners.Aber wenn es versucht, die erste Datei aus dem ersten Verzeichnis herunterzuladen, bekomme ich wieder ein Timeout bei FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); Zusätzliche Info: Wenn ich meine Firewall abschalte, dann funktioniert alles und die Dateien werden geladen: Code unten: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace GetBotfilesFromFTP { class Program { string sFtpServerIP = "SERVERIP"; string sFtpUserID = "USERID"; string sFtpPassword = "USERPASSWORT"; string sRemoteDir = "ftp://w01a18b1.kasserver.com/"; static void Main(string[] args) { Program self = new Program(); string url = "ftp://" + self.sFtpServerIP + "/"; NetworkCredential credentials = new NetworkCredential(); credentials.Password = self.sFtpPassword; credentials.UserName = self.sFtpUserID; self.GetFileListAndContinue(self.sRemoteDir, "C:/"); } public void GetFileListAndContinue(string RemoteDirectory, string sLocalDirectory) { string sActualRemoteDirectory = RemoteDirectory; string sActualDirectory = sLocalDirectory; string[] downloadFiles; StringBuilder result = new StringBuilder(); WebResponse response = null; StreamReader reader = null; try { FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(RemoteDirectory)); reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential(sFtpUserID, sFtpPassword); reqFTP.Method = WebRequestMethods.Ftp.ListDirectory; reqFTP.Proxy = null; reqFTP.KeepAlive = false; reqFTP.UsePassive = true; response = reqFTP.GetResponse(); reader = new StreamReader(response.GetResponseStream()); string line = reader.ReadLine(); while (line != null) { result.Append(line); result.Append("\n"); line = reader.ReadLine(); } // to remove the trailing '\n' result.Remove(result.ToString().LastIndexOf('\n'), 1); string[] files = result.ToString().Split('\n'); string item = "."; files = files.Where(e => e != item).ToArray(); Console.WriteLine(String.Join(",", files)); item = ".."; files = files.Where(e => e != item).ToArray(); Console.WriteLine(String.Join(",", files)); foreach (string file in files) { if (file.Contains(".")) { Download(file, RemoteDirectory, sLocalDirectory); } else { sActualDirectory = sLocalDirectory; sActualRemoteDirectory = RemoteDirectory; sActualDirectory = sActualDirectory + file + "/"; sActualRemoteDirectory = sActualRemoteDirectory + file + "/"; createdir(sActualDirectory); GetFileListAndContinue(sActualRemoteDirectory, sActualDirectory); } } } catch (Exception ex) { if (reader != null) { reader.Close(); } if (response != null) { response.Close(); } } } private void Download(string file, string RemoteDirectory, string sLocalPath) { try { string uri = RemoteDirectory + file; Uri serverUri = new Uri(uri); if (serverUri.Scheme != Uri.UriSchemeFtp) { return; } FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri)); reqFTP.Credentials = new NetworkCredential(sFtpUserID, sFtpPassword); reqFTP.KeepAlive = false; reqFTP.Method = WebRequestMethods.Ftp.DownloadFile; reqFTP.UseBinary = true; reqFTP.Proxy = null; reqFTP.UsePassive = false; FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); Stream responseStream = response.GetResponseStream(); FileStream writeStream = new FileStream(sLocalPath + file, FileMode.Create); int Length = 2048; Byte[] buffer = new Byte[Length]; int bytesRead = responseStream.Read(buffer, 0, Length); while (bytesRead > 0) { writeStream.Write(buffer, 0, bytesRead); bytesRead = responseStream.Read(buffer, 0, Length); } writeStream.Close(); response.Close(); } catch (WebException wEx) { } catch (Exception ex) { } } //// In this part i create the sub-directories. /// public void createdir(string path) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } } } }
  3. @mwiederkehr Do you have an idea why my programm got now again timeout. I used how you said the reqFTP.UsePassive = true and it connect and load my first folder. But after that it timeout again at the same line. Local with active mode it works an load all folders and files. Ach ist das hier ein Deutsches Forum Das wusste ich nicht. Dachte auf englisch erreich ich schneller wen. @mwiederkehr gerne auch hier antworten habe dazu noch mal ein neues Thema geöffnet Additional Info: I tested it now local with passive mode and that works too dont know why it dont works on the server
  4. I have now deaktivated my firewall and it works. Any idea what i need to do in the firewall that it works with an active firewall?
  5. Hey i have bought a Windows Server 2019 on Strato. Now i want to download fiels from an ftp to this server via. my Application. The Application works fine on my local PC. It connects to the ftp and download all files. But on the Windows Server i alltimes get a timerout error at response = reqFTP.GetResponse(); If i use filezilla on the Windows Server it works. I can manually download the files. I think its something with the server because the code is working local but here is my code: public void GetFileListAndContinue(string RemoteDirectory, string sLocalDirectory) { string sActualRemoteDirectory = RemoteDirectory; string sActualDirectory = sLocalDirectory; string[] downloadFiles; StringBuilder result = new StringBuilder(); WebResponse response = null; StreamReader reader = null; try { FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(RemoteDirectory)); reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential(sFtpUserID, sFtpPassword); reqFTP.Method = WebRequestMethods.Ftp.ListDirectory; reqFTP.Proxy = null; reqFTP.KeepAlive = false; reqFTP.UsePassive = false; response = reqFTP.GetResponse(); reader = new StreamReader(response.GetResponseStream()); string line = reader.ReadLine(); while (line != null) { result.Append(line); result.Append("\n"); line = reader.ReadLine(); } // to remove the trailing '\n' result.Remove(result.ToString().LastIndexOf('\n'), 1); string[] files = result.ToString().Split('\n'); string item = "."; files = files.Where(e => e != item).ToArray(); Console.WriteLine(String.Join(",", files)); item = ".."; files = files.Where(e => e != item).ToArray(); Console.WriteLine(String.Join(",", files)); foreach (string file in files) { if (file.Contains(".")) { Download(file, RemoteDirectory, sLocalDirectory); } else { sActualDirectory = sLocalDirectory; sActualRemoteDirectory = RemoteDirectory; sActualDirectory = sActualDirectory + file + "/"; sActualRemoteDirectory = sActualRemoteDirectory + file + "/"; createdir(sActualDirectory); GetFileListAndContinue(sActualRemoteDirectory, sActualDirectory); } } } catch (Exception ex) { if (reader != null) { reader.Close(); } if (response != null) { response.Close(); } } }
×
×
  • Neu erstellen...