0

我正在使用 SharpSSH 将文件上传到远程机器:

public override void WriteFile(string directoryName, string fileName, string localFilePath) {
    sftp.Put(localFilePath, directoryName + "/" + fileName);
}

问题是文件的权限是rw-r-----。这可以防止接收应用程序将文件移动到将要处理它的另一个文件夹。我在另一台本地安装在我的桌面(虚拟机)上的 unix 机器上对此进行了测试,但是文件的权限设置为 rwxrwxrwx。
使用同一用户使用 WinSCP 传输文件时,文件的权限设置为 rwxrwxrwx。我发现 WinSCP 被配置为提供这些过于广泛的权限,所以我想也这样做。我添加了这一行。

public override void WriteFile(string directoryName, string fileName, string localFilePath) {
    sftp.Put(localFilePath, directoryName + "/" + fileName);
    sshExec.RunCommand(@"chmod 666 " + directoryName + "/" + fileName);
}

但它不会更改文件的权限。我是否错误地运行了命令?

4

2 回答 2

0

命令的输出是什么?可能是您没有运行 chmod 的权限?尝试“sudo chmod 666”

于 2012-11-14T13:37:39.613 回答
0

如果您正在运行使用“sudo”作为 ubuntu 的 SO,除非您编辑 sudoers 文件并允许 chmod 在没有 sudo 密码的情况下工作,否则您将无法执行该操作。

检查这个没有密码的Sudo

此外,使用其他 RunCommand 重载通过引用 stdOut 来获取命令的输出:

string stErr = string.Empty;
string stdOut = string.Empty;
Result = Ssh.RunCommand("@"chmod 666 " + directoryName + "/" + fileName",ref stdOut, ref stErr);
于 2012-11-14T13:46:13.697 回答