Search code examples
c#unixsharpssh

Unix / SharpSSH - sshExec.RunCommand(@"chmod 666...) isn't changing file's permission


I'm using SharpSSH to upload files to a remote machine:

public override void WriteFile(string directoryName, string fileName, string localFilePath) {
    sftp.Put(localFilePath, directoryName + "/" + fileName);
}

The problem is that the file's permission is rw-r-----. This prevents a receiving application from moving the file to another folder where it will be processed. I tested this on another unix machine which is installed locally on my desktop (virtual machine), but there the file's permission is set to rwxrwxrwx.
When transferring file with WinSCP using the same user, the file's permissions are set to rwxrwxrwx. I found that WinSCP was configured to give these overly extensive permissions, so I thought to do the same. I added this line.

public override void WriteFile(string directoryName, string fileName, string localFilePath) {
    sftp.Put(localFilePath, directoryName + "/" + fileName);
    sshExec.RunCommand(@"chmod 666 " + directoryName + "/" + fileName);
}

But it isn't changing the file's permission. Am I running the command incorrectly?


Solution

  • What is output of the command? May be you don't have permissions to run chmod? Try "sudo chmod 666"