Umut Zerman

Umut Zerman

  • NA
  • 10
  • 1.1k

Uploading a File into NAS

Sep 17 2018 2:03 PM
Hi there,
i've got a problem to Upload a File to a Nas.. I'm a newbie from Germany.
So the Upload is creating the File i want to, but with 0KB.
 Here is my code:
 
  1. var client = new SftpClient("x.x.x.x", 22, "xxx""xxx");  
  2.                 client.Connect();  
  3.                 client.BufferSize = 1024;  
  4.                 Console.WriteLine("Verbindung wird hergestellt");  
  5.                 if (client.IsConnected)  
  6.                 {  
  7.                     Console.WriteLine("Verbindung hergestellt");  
  8.                     var fileStream = new FileStream(uploadfile, FileMode.OpenOrCreate);  
  9.                     Console.WriteLine("Stream erstellt");  
  10.                     if (fileStream != null)  
  11.                     {  
  12.                         //Pc Nummer die die Datei empfängt ist i  
  13.                         for (var i = 1; i < 25; i++)  
  14.                         {  
  15.                             Console.WriteLine("Stream gestartet");  
  16.                             string pcnummer = "";  
  17.                             if (i < 10)  
  18.                             { pcnummer = "0" + i.ToString(); }  
  19.                             else  
  20.                             {  
  21.                                 pcnummer = i.ToString();  
  22.                             }  
  23.                             pcnummer = raum + pcnummer;  
  24.                             client.UploadFile(fileStream, "/share/" + pcnummer + "/" + f.Name,null);  
  25. // Ich habs mal mit der Zeile versucht.. aber ohne Erfolg   
  26.                            //client.ChangePermissions("/share/" + pcnummer + "/" + f.Name, 777);  
  27.                             Console.WriteLine("Dateien für " + pcnummer + " hochgeladen");  
  28.                         }  
  29.                         client.Dispose();  
  30.                         Console.WriteLine("Dateien für alle hochgeladen ");  
  31.                         MessageBox.Show("Dateien für alle hochgeladen ");  
  32.                         //client.UploadFile(fileStream, "/share/" + f.Name, null);  
  33.   
  34.                     }  
  35.                 } 
 so what do you think is my fault?