0 votes
by (150 points)
edited

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 (144k points)
edited
 
Best answer

Use Sftp.SetAttributes method:

C#:

// create an Sftp instance and connect/authenticate
Sftp sftp = new Sftp();
sftp.Connect(serveName);
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)
edited

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

by (58.9k points)
edited

Hi,

here is an equivalent code for powershell:

$sftp = New-Object Rebex.Net.Sftp
$sftp.Connect("server")
$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)
$sftp.Disconnect()

Learn to use Rebex SFTP and other components from PowerShell.

by
How to select all files in remote directory?
by (144k 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.
...