gpt4 book ai didi

c# - 使用 SSH.NET SftpClient 设置扩展文件属性

转载 作者:行者123 更新时间:2023-11-30 17:30:59 25 4
gpt4 key购买 nike

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

这是我尝试设置扩展属性的方式

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 连接。

最佳答案

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

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


另请参阅这些讨论:

以及 SFTP 规范的相关部分:

关于c# - 使用 SSH.NET SftpClient 设置扩展文件属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48687079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com