0 votes
by (150 points)

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

Applies to: Rebex SFTP

1 Answer

+1 vote
by (147k points)
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.

by (240 points)

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

by (58.9k points)


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.

How to select all files in remote directory?
by (147k 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 https://www.rebex.net/sftp.net/features/single-file-operations.aspx, https://www.rebex.net/sftp.net/features/multiple-files-operations.aspx or https://www.rebex.net/sftp.net/features/directory-operations.aspx - converting them to PowerShell should be quite straighforward.