简体   繁体   中英

Setting the extended file attributes using SSH.NET SftpClient

I am trying to use the extended file attribute to store some information after I uploaded a file into remote machine (Ubuntu 16.04 LTS) from Windows using Renci SSH.NET SFTP library. But the attributes are not getting preserved?

This how I am trying to set the extended attributes

SftpFileAttributes fileAttrs = sftpClient.GetAttributes(remoteFilePath);
IDictionary<string, string> additionalAttrs = new Dictionary<string, string>();
additionalAttrs.Add(new KeyValuePair<string, string>("user.from", "abc"));
additionalAttrs.Add(new KeyValuePair<string, string>("user.to", "xyz"));
fileAttrs =
    new SftpFileAttributes(
        fileAttrs.LastAccessTime, fileAttrs.LastWriteTime, fileAttrs.Size,
        fileAttrs.UserId, fileAttrs.GroupId, 222, additionalAttrs);
sftpClient.SetAttributes(remoteFilePath, fileAttrs);

So, can you help me how to approach this problem? Note that : The remote machine is configured to allow only SFTP connection for security reason.

You cannot add random extended attributes like user.from . You can add only attributes that your server explicitly supports.

You didn't specify what SFTP server are you using. But as you are connecting to Ubuntu server, one can assume, that it's the the most widespread *nix SFTP server, OpenSSH. And OpenSSH does not support any extended attribute . It silently ignores all of them.


See also these discussions:

And the relevant section of SFTP specification:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM