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 (121,330 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.