Setting SFTP File Properties

0 votes
asked Aug 25, 2010 by Andy Blum (150 points)
edited Sep 10, 2014

How do I use the Rebex API to set file properties on a remote file server.

Applies to: Rebex SFTP

1 Answer

+1 vote
answered Aug 26, 2010 by Lukas Pokorny (128,250 points)
edited Sep 10, 2014
Best answer

Use Sftp.SetAttributes method:


// create an Sftp instance and connect/authenticate
Sftp sftp = new Sftp();
sftp.Login(userName, password);

// specify attributes
SftpAttributes attributes = new SftpAttributes();
attributes.Modified = DateTime.Now;
attributes.Permissions = SftpPermissions.OwnerWrite | SftpPermissions.OwnerRead;

// set attributes of a remote file
sftp.SetAttributes("file.txt", attributes);

If you prefer VB.NET, please let me know.

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

Hi and thanks for responding. My issue is not with C# or VB but with making the calls via PowerShell.

commented Sep 10, 2014 by Tomas Knopp (58,890 points)
edited Sep 10, 2014


here is an equivalent code for powershell:

$sftp = New-Object Rebex.Net.Sftp
$sftp.Login("user", "password")
$attributes = New-Object Rebex.Net.SftpAttributes
$attributes.Modified = [System.DateTime]::Now
$attributes.Permissions = [Rebex.Net.SftpPermissions] "OwnerWrite, OwnerRead"
$sftp.SetAttributes("file.txt", $attributes)

Learn to use Rebex SFTP and other components from PowerShell.

commented Aug 23, 2021 by anonymous
How to select all files in remote directory?
commented Aug 23, 2021 by Lukas Pokorny (128,250 points)
Hello Asyraf, what do you mean by "selecting" files? Would you like to retrieve a list of files in a remote directory, or download specified files? In any case, please check out the relevant C#/VB.NET code snippets at, or - converting them to PowerShell should be quite straighforward.