Scp set permission

0 votes
asked Jun 28, 2016 by taskin (150 points)

Hi,
i am testing Scp module, i want to upload files and set permissions to be executable at same time. What options do i have? I understand i could open 2 connections (ssh&scp) but this does not look very efficient.
taskin

1 Answer

0 votes
answered Jun 28, 2016 by Lukas Matyska (60,650 points)
selected Jun 29, 2016 by taskin
 
Best answer

Hello,

unfortunately, we doesn't support setting permissions in SCP (permissions are set to 644 by default).

The SCP is quite legacy file transfer protocol and we added SCP support for situations where SFTP cannot be used.

Is it possible for you to use SFTP which is quite newer protocol?

Using SFTP you can set permissions like this:

// initialize SFTP client object
var client = new Sftp();
client.Connect(...);
client.Login(...);

// prepare new file attributes
var attributes = new SftpAttributes();
attributes.Permissions = (SftpPermissions)Convert.ToInt32("755", 8);

// set attributes of a file
client.SetAttributes("/data/file.txt", attributes);
...