Search in sources :

Example 11 with FileAttrs

use of com.jn.agileway.ssh.client.sftp.attrs.FileAttrs in project agileway by fangjinuo.

the class Sftps method getPosixPermission.

public static PosixFilePermissions getPosixPermission(SftpFile sftpFile) throws IOException {
    FileAttrs attrs = sftpFile.getAttributes();
    int[] groupIds = sftpFile.getSession().getSshConnection().getGroupIds();
    boolean inGroup = Collects.newArrayList(PrimitiveArrays.wrap(groupIds)).contains(attrs.getGid());
    int uid = sftpFile.getSession().getSshConnection().getUid();
    boolean isOwner = attrs.getUid() == uid;
    return new PosixFilePermissions(attrs.getFileMode().getPermissionsMask(), isOwner, inGroup);
}
Also used : FileAttrs(com.jn.agileway.ssh.client.sftp.attrs.FileAttrs) PosixFilePermissions(com.jn.langx.util.io.file.PosixFilePermissions)

Example 12 with FileAttrs

use of com.jn.agileway.ssh.client.sftp.attrs.FileAttrs in project agileway by fangjinuo.

the class Sftps method chown.

public static void chown(final SftpSession session, String path, int uid) throws IOException {
    FileAttrs attrs = session.stat(path);
    FileAttrs attrs2 = new FileAttrs();
    attrs2.setUid(uid);
    attrs2.setGid(attrs.getGid());
    session.setStat(path, attrs2);
}
Also used : FileAttrs(com.jn.agileway.ssh.client.sftp.attrs.FileAttrs)

Aggregations

FileAttrs (com.jn.agileway.ssh.client.sftp.attrs.FileAttrs)12 FileMode (com.jn.agileway.ssh.client.sftp.attrs.FileMode)6 FileType (com.jn.agileway.ssh.client.sftp.attrs.FileType)2 NoSuchFileSftpException (com.jn.agileway.ssh.client.sftp.exception.NoSuchFileSftpException)2 SFTPv3FileHandle (ch.ethz.ssh2.SFTPv3FileHandle)1 SshConnection (com.jn.agileway.ssh.client.SshConnection)1 SshConnectionConfig (com.jn.agileway.ssh.client.SshConnectionConfig)1 SftpException (com.jn.agileway.ssh.client.sftp.exception.SftpException)1 PosixFilePermissions (com.jn.langx.util.io.file.PosixFilePermissions)1 SFTPv3FileHandle (com.trilead.ssh2.SFTPv3FileHandle)1 File (java.io.File)1