使用SSH.NET SftpClient设置扩展文件属性 [英] Setting the extended file attributes using SSH.NET SftpClient

查看:56
本文介绍了使用SSH.NET SftpClient设置扩展文件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我使用Renci SSH.NET SFTP库将文件从Windows上传到远程计算机(Ubuntu 16.04 LTS)后,我尝试使用扩展文件属性来存储一些信息.但是属性没有得到保留吗?

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);

那么,您能帮我解决这个问题吗?请注意:出于安全原因,远程计算机配置为仅允许SFTP连接.

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.

推荐答案

您不能添加随机扩展属性,例如 user.from .您只能添加服务器明确支持的属性.

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

您没有指定正在使用的SFTP服务器.但是,当您连接到Ubuntu服务器时,可以假设它是最广泛的* nix SFTP服务器OpenSSH.而且OpenSSH 不支持任何扩展属性.它静默地忽略所有这些内容.

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.

另请参阅以下讨论:

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

以及SFTP规范的相关部分:

And the relevant section of SFTP specification:

这篇关于使用SSH.NET SftpClient设置扩展文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆