这段代码将执行您想要的操作:
ChannelSftp channel = (ChannelSftp)session.openChannel("sftp");
SftpATTRS attrs = channel.lstat(fileOnServer)
boolean userHasPermissionsToWriteFile = attrs != null && ((attrs.getPermissions() & 00200) != 0) && attrs.getUId() != 0;
Run Code Online (Sandbox Code Playgroud)
在哪里
attrs.getUId() != 0
Run Code Online (Sandbox Code Playgroud)
检查用户不是 root