title: Unable to upload a file SFTP using SSH.NET in C# - Permission Denied
body: <p>I am trying to upload a file using SFTP protocol using C# using SSH.NET library. Below is the code I am using </p>
  
  <pre><code>FileInfo f=new FileInfo("C:\\mdu\\abcd.xml");            
  string uploadfile=f.FullName;    
  Console.WriteLine(f.Name);
  Console.WriteLine("uploadfile"+uploadfile);
  var client = new SftpClient(host, port, username, password);
  client.Connect();
  if(client.IsConnected){
         Console.WriteLine("I AM CONNECTED");
  }
  var fileStream = new FileStream(uploadfile, FileMode.Open);  
  if(fileStream!=null){
              Console.WriteLine("YOU ARE NOT NULL");
  }
  client.BufferSize = 4 * 1024; 
  client.UploadFile(fileStream, f.Name,null);
  client.Disconnect();
  client.Dispose();
  </code></pre>
  
  <p>I am able to connect and the <code>filestream</code> is also not NULL. But I am getting <code>PermissionDeniedException</code> while attempting to upload a file. </p>
  
  <pre class="lang-none prettyprint-override"><code>Unhandled Exception: Renci.SshNet.Common.SftpPermissionDeniedException: Permission denied
     at Renci.SshNet.Sftp.SftpSession.RequestOpen(String path, Flags flags, Boolean nullOnError)
     at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action`1 uploadCallback)
     at Renci.SshNet.SftpClient.UploadFile(Stream input, String path, Boolean canOverride, Action`1 uploadCallback)
     at Renci.SshNet.SftpClient.UploadFile(Stream input, String path, Action`1 uploadCallback)
     at movemsi.Program.UploadFile()
     at movemsi.Program.Main(String[] args)
  </code></pre>
  
  <p>Is there any settings I am missing from the above code. Any help is much appreciated.</p>