【发布时间】:2017-07-12 21:58:01
【问题描述】:
我正在使用 JSch 来 sftp 文件。上传后,我更改了文件的权限。但是如何更改所有者?我找不到很好的例子。我想要
chown Administrator:Administrators filename.exe
就像你在 linux 中所做的那样,但是 JSch chown 命令接受一个整数,而不是 owner:group 的字符串。这是什么废话?
这是我的一些代码
jSch = new JSch();
if (useKey) jSch.addIdentity(privateKey);
session = jSch.getSession( user, host, port );
if (!useKey) {
session.setPassword(pass);
session.setConfig( "PreferredAuthentications", "password" );
}
session.setConfig("StrictHostKeyChecking", "no");
session.connect(FTP_TIMEOUT);
channel = session.openChannel("sftp");
sftp = (ChannelSftp) channel;
sftp.connect(FTP_TIMEOUT);
sftp.put(fis,file.getName());
String permissions = "744";
int octal = Integer.parseInt(permissions,8); //jsh uses octal, not decimal
if (file.getName().endsWith(".exe")) { //make exe files executable
sftp.chmod(octal,file.getName());
sftp.chown(this-is-an-integer-not-a-string, file.getName());
}
【问题讨论】: