I'm using SharpSSH to write files to a unix machine. The files are supposed to be read and then deleted up by another application which resides on the unix machine.
The problem is that the unix application does not have rights to delete the file. I can see the file's permissions are rw-r-----
Here is my code:
public override void WriteFileg(string directoryName, string fileName, string responseText, host, username, password, port) {
// Write the file locally
TextWriter writer = new StreamWriter("TempForSftp.txt");
writer.WriteLine(responseText);
writer.Close();
// Transfer the local file
Sftp sftp = new Sftp(host, username, password);
sftp.Connect(int.Parse(port));
sftp.Put("TempForSftp.txt", directoryName + "/" + fileName);
sftp.Close();
}
How do I set different permissions?
SharpSsh library seems to implement very basic functionality for SFTP, which doesn't implement method to set file permissions. You can try to set permissions via SSH shell (in SSH thereis subsystem channel, which executes one command, so you can call chmod) if they support this, otherwise you should search for other C# library. Luckily, there is a bunch of them available.