c# - FTP上传后更改文件权限
问题描述
我正在将桌面文件夹中的文件上传到 Windows Server 2012 服务器。
上传正常进行,但我需要更改上传文件的读取和删除权限。
我怎样才能在这段代码中做到这一点?
string ftpIPServidor = "XXXX";
string ftpUsuarioID = "XX";
string ftpSenha = "XXXXXXX";
FileInfo _arquivoInfo = new FileInfo(_nomeArquivo);
string uri = "ftp://" + ftpIPServidor + "/" + _arquivoInfo.Name;
FtpWebRequest requisicaoFTP;
requisicaoFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpIPServidor + "/" + _arquivoInfo.Name));
requisicaoFTP.Credentials = new NetworkCredential(ftpUsuarioID, ftpSenha);
requisicaoFTP.KeepAlive = false;
requisicaoFTP.Method = WebRequestMethods.Ftp.UploadFile;
requisicaoFTP.UseBinary = true;
requisicaoFTP.ContentLength = _arquivoInfo.Length;
// Define o tamanho do buffer para 2kb
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int _tamanhoConteudo;
FileStream fs = _arquivoInfo.OpenRead();
var horaAgora = DateTime.Now;
try
{
Stream strm = requisicaoFTP.GetRequestStream();
_tamanhoConteudo = fs.Read(buff, 0, buffLength);
while (_tamanhoConteudo != 0)
{
// Escreve o conteudo a partir do arquivo para o stream FTP
strm.Write(buff, 0, _tamanhoConteudo);
_tamanhoConteudo = fs.Read(buff, 0, buffLength);
}
strm.Close();
fs.Close();
Console.WriteLine(horaAgora + " :> Upload of " + _arquivoInfo.Name);
fi.Delete();
}
catch (Exception ex)
{
Console.WriteLine(horaAgora + " :> Err " + _arquivoInfo.Name);
}
解决方案
包中有调用的扩展方法GetAccessControl
和SetAccessControl
System.IO.FileSystem.AccessControl
更多信息在这里
推荐阅读
- java - 如何修复嵌套的?
- .net - 如何访问附加了属性的参数?
- docker - docker-compose: varnish+apache2 返回 503 错误`Backend fetch failed`
- full-text-search - 在 ClickHouse 中搜索文本时内存不足
- azure-cosmosdb - CosmosDb 和 RU 用于同一查询
- flutter - 应用再次启动时如何使用共享偏好打开特定屏幕
- json - DRF:发出外部请求并构建序列化程序
- node.js - 如何在 Op 中分配 Sequelize 的比较运算符
- javascript - 如何处理 Caesars Cipher (Javascript) 中的负偏移
- c# - ASP.NET Core Razor 页面 - 不绑定 POST 请求