Setting the extended file attributes using SSH.NET SftpClient

纵然是瞬间 提交于 2020-01-13 17:58:28

问题


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.


回答1:


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:

  • Implementation of xattr in sftp-server for sshfs (OpenSSH)
  • Support extended attribute SFTP requests (ProFTPD)

And the relevant section of SFTP specification:

  • https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02#section-5


来源:https://stackoverflow.com/questions/48687079/setting-the-extended-file-attributes-using-ssh-net-sftpclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!