对于文件,我只需要更改用户权限,
Actual output is :::--x-wx--T
Expected output is::rw-------
这是我的示例代码:
String serverFileName = "FileInServer.txt";
sftp.upload("src/test/java/com/filecreation/testfile/"+fileName+".txt",serverFileName);
Session session = null;
JSch jsch=new JSch();
session=jsch.getSession("user", "host", port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
if (!channel.isConnected())
channel.connect();
channel.chmod(600,"/home/user/FileInServer.txt");
channel.disconnect();
session.disconnect();
答案 0 :(得分:2)
channel.chmod(600,"/home/user/FileInServer.txt");
您看到与chmod一起使用的权限值(例如644
或755
)是八进制(以8为底),而不是十进制。当您可能想要八进制0600时,在此处指定十进制600:
channel.chmod(0600,"/home/user/FileInServer.txt");
^-- Leading 0 indicating an octal number