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 (124,570 points)
edited Sep 10, 2014
 
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.

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

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.

commented Aug 23 by asyraf (100 points)
How to select all files in remote directory?
commented Aug 23 by Lukas Pokorny (124,570 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.
...