Setting file permissions on remote server via sFTP and PowerShell

+1 vote
asked Sep 10, 2014 by shunt01 (240 points)
edited Sep 10, 2014

Hi All,

I am trying to set the permissions of a file that I have moved to a new directory on the remote server. I am connected to the server via sFTP and the script is being run through PowerShell.

Any help would be great!.

Scott

Applies to: Rebex SFTP

2 Answers

+1 vote
answered Sep 10, 2014 by Tomas Knopp (58,890 points)
edited Sep 10, 2014
 
Best answer

Use this code to set remote file permissions via SFTP from PowerShell:

$sftp = New-Object Rebex.Net.Sftp
$sftp.Connect("server")
$sftp.Login("user", "password")
$attributes = New-Object Rebex.Net.SftpAttributes
$attributes.Permissions = [Rebex.Net.SftpPermissions] "OwnerWrite, OwnerRead"
$sftp.SetAttributes("file.txt", $attributes)
$sftp.Disconnect()

Learn to use Rebex SFTP and other components from PowerShell.

commented Sep 10, 2014 by shunt01 (240 points)
edited Sep 10, 2014

Thanks Tomas that worked! BTW you are also right that you have to list out each of the permissions.

0 votes
answered Sep 10, 2014 by Tomas Knopp (58,890 points)
edited Sep 10, 2014
...