title: How to write content to file on linux SFTP server using SshClient?
body: <p>I am dealing with Linux SFTP server using .Net (SshClient) code, so I am creating folder on SFTP server and creating files also. For this I am using following code,</p>
  
  <pre><code>using (var client = new SshClient(WebConfigurationManager.AppSettings["SftpServer"], WebConfigurationManager.AppSettings["SftpUserName"], WebConfigurationManager.AppSettings["SftpPassword"]))
  {
     client.Connect();
  
      if (client.IsConnected)
      {
          //  Check if the Folder Already Exists 
          var ifExists = client.RunCommand("cat /etc/passwd  | grep -w " + ftpUserName);
          // If the Folder and User Does Not exists , create both 
          if (string.IsNullOrEmpty(ifExists.Result))
          {
              client.RunCommand("echo Asdf@123 | sudo -S mkdir /sftpusers/" + ftpUserName);
              client.RunCommand("echo Asdf@123 | sudo -S mkdir /sftpusers/" + ftpUserName + "/import"); //  this is for creating folder
              client.RunCommand("echo Asdf@123 | sudo -S mkdir /sftpusers/" + ftpUserName + "/schema");
              client.RunCommand("echo Asdf@123 | sudo -S touch /sftpusers/" + ftpUserName + "/schema/fileName.txt");
              sftpCreated = true;
          }
      }
      client.Disconnect();
  }
  </code></pre>
  
  <p>This code is working file to create a folder and text files on SFTP but Now I am trying to write data to that file, and for that I am using following code,</p>
  
  <pre><code>client.RunCommand("echo Asdf@123 | sudo -S echo hi user &gt;&gt; /sftpusers/asb/schema/filename.txt");
  </code></pre>
  
  <p>But it is not working. I am getting error says <code>Error = "bash: /sftpusers/asb/schema/filename.txt: Permission denied\n</code>.</p>
  
  <p>I am little confused that, if same command i.e. <code>echo pwd | sudo -s cmd</code>
  is creating folder, files on SFTP server then why it failing while writing content to file.</p>
  
  <p>Need help on this as early as possible.</p>