2015-01-25 9 views
1

C# 콘솔 응용 프로그램에서 FTP를 사용하여 파일을 다운로드하려고합니다. 그러나 이제는 경로가 올바르지 만 "550 파일을 찾을 수 없음"이라는 오류 메시지가 항상 나타납니다.C# 단일 파일 FTP 다운로드

서버에 연결된 현재 경로를 반환하는 방법이 있습니까?

// lade datei von FTP server 
     string ftpfullpath = "ftp://" + Properties.Settings.Default.FTP_Server + Properties.Settings.Default.FTP_Pfad + "/" + Properties.Settings.Default.FTP_Dateiname; 
     Console.WriteLine("Starte Download von: " + ftpfullpath); 
     using (WebClient request = new WebClient()) 
     { 
      request.Credentials = new NetworkCredential(Properties.Settings.Default.FTP_User, Properties.Settings.Default.FTP_Passwort); 
      byte[] fileData = request.DownloadData(ftpfullpath); 

      using (FileStream file = File.Create(@path + "/tmp/" + Properties.Settings.Default.FTP_Dateiname)) 
      { 
       file.Write(fileData, 0, fileData.Length); 
       file.Close(); 
      } 
      Console.WriteLine("Download abgeschlossen!"); 
     } 

편집 내 실수. 여전히 동일한 오류가 발생하는 파일 경로가 수정되었습니다. 하지만 정확한 파일 경로 인 FileZilla에 연결하면됩니다.

답변

1

마지막으로 System.Net.FtpClient (https://netftp.codeplex.com/releases/view/95632)를 사용하고 다음 코드를 사용하여 솔루션을 찾았습니다.

// aktueller pfad 
     string apppath = Directory.GetCurrentDirectory(); 

     Console.WriteLine("Bereite Download von FTP Server vor!"); 

     using (var ftpClient = new FtpClient()) 
     { 
      ftpClient.Host = Properties.Settings.Default.FTP_Server; 
      ftpClient.Credentials = new NetworkCredential(Properties.Settings.Default.FTP_User, Properties.Settings.Default.FTP_Passwort); 
      var destinationDirectory = apppath + "\\Input"; 

      ftpClient.Connect(); 

      var destinationPath = string.Format(@"{0}\{1}", destinationDirectory, Properties.Settings.Default.FTP_Dateiname); 
      Console.WriteLine("Starte Download von " + Properties.Settings.Default.FTP_Dateiname + " nach " + destinationPath); 
      using (var ftpStream = ftpClient.OpenRead(Properties.Settings.Default.FTP_Pfad + "/" + Properties.Settings.Default.FTP_Dateiname)) 
      using (var fileStream = File.Create(destinationPath , (int)ftpStream.Length)) 
      { 
       var buffer = new byte[8 * 1024]; 
       int count; 
       while ((count = ftpStream.Read(buffer, 0, buffer.Length)) > 0) 
       { 
        fileStream.Write(buffer, 0, count); 
       } 
      } 
     } 
0

파일 이름이 잘못되었습니다. 첫 번째 행은 ftpfullpath에 설정 한 것과 다른 이름을 씁니다. 우리는 ftpfullpath를 설정할 때 첫 줄에 FTP_Dateiname 대신 FTP_Pfad를 사용합니다.

가) '... 문자열 ftpfullpath'실제로 한 후에 고객의 첫 번째 라인을 이동 무슨 일이 일어나고 있는지

을보고 Console.WriteLine로 변경 ("스타터는 폰 다운로드 :"+ ftpfullpath을);

+0

수정 됨. 위 참조. 여전히 같은 오류. 실수를 지적 해 주셔서 감사합니다. 몇 시간 씩 시도해 보았습니다. 웹에서 찾은 여러 가지 해결책이 있지만 항상 같은 결과를 얻었습니다. –

+0

FTP_Server 이후 /가 누락되지 않았다고 가정합니다. (나는 FTP_Pfad가 디렉토리라고 가정하고있다.) – Tim

+0

또 다른 가능성은 당신이 다른 사용자/패스워드를 사용하고 있고 ftp 서버에 다른 루트 디렉토리를 얻고 있다는 것이다. – Tim