+1 vote
by (240 points)
edited

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
by (58.9k points)
edited
 
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.

by (240 points)
edited

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

0 votes
by (58.9k points)
edited
...