Question

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?

Was it helpful?

Solution

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

OTHER TIPS

If you are running SO that uses "sudo" as ubuntu you cant perform the operation unless you edit the sudoers file and permit chmod to work without sudo password.

Check this: Sudo without password

In addition use the other RunCommand overload to get the output from the command by reference to stdOut:

string stErr = string.Empty;
string stdOut = string.Empty;
Result = Ssh.RunCommand("@"chmod 666 " + directoryName + "/" + fileName",ref stdOut, ref stErr);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top