0

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?

Yoav
  • 2,077
  • 6
  • 27
  • 48
  • when you say 'taking the file and process ing it' do you mean reading, changing and writing back ? – Hugh Jones Nov 14 '12 at 12:23
  • It moves the file to another folder. Another component will then read the file and act on it. I'll update my question to clarify. – Yoav Nov 14 '12 at 12:27
  • I may be being a bit simplisitic here but could it not just be a simple permissions issue - the second ap cannot delete the file because it is not the owner? ... Ok - that is begging the question ... – Hugh Jones Nov 14 '12 at 12:33
  • I'm not being very clear. My problem is that chmod isn't changing the file's permission. – Yoav Nov 14 '12 at 12:37
  • What is output of the command? May be you don't have permissions to run chmod? Try "sudo chmod 666" – Alex Nov 14 '12 at 12:43
  • @Alexander S: I would kiss you if you were here. I've been struggling with this for more then a week. Thank you very much. Please write it in an answer so I can select it. – Yoav Nov 14 '12 at 13:27

2 Answers2

0

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

Alex
  • 811
  • 7
  • 11
0

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);
Carlos Landeras
  • 11,025
  • 11
  • 56
  • 82