Search in sources :

Example 11 with FileMode

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

the class SynergySftps method fromSftpFileAttributes.

public static FileAttrs fromSftpFileAttributes(SftpFileAttributes attributes) {
    if (attributes == null) {
        return null;
    }
    FileAttrs attrs = new FileAttrs();
    if (attributes.hasSize()) {
        attrs.setSize(attributes.getSize().longValue());
    }
    if (attributes.hasAccessTime()) {
        attrs.setAccessTime(attributes.getAccessedTime().bigIntValue().intValue());
    }
    if (attributes.hasModifiedTime()) {
        attrs.setModifyTime(attributes.getModifiedTime().bigIntValue().intValue());
    }
    if (attributes.hasUID()) {
        String uid = attributes.getUID();
        if (Numbers.isNumber(uid)) {
            attrs.setUid(Integer.parseInt(uid));
        }
    }
    if (attributes.hasGID()) {
        String gid = attributes.getGID();
        if (Numbers.isNumber(gid)) {
            attrs.setGid(Integer.parseInt(gid));
        }
    }
    FileType fileType = FileType.UNKNOWN;
    if (attributes.isFile()) {
        fileType = FileType.REGULAR;
    } else if (attributes.isDirectory()) {
        fileType = FileType.DIRECTORY;
    } else if (attributes.isBlock()) {
        fileType = FileType.BLOCK_SPECIAL;
    } else if (attributes.isCharacter()) {
        fileType = FileType.CHAR_SPECIAL;
    } else if (attributes.isFifo()) {
        fileType = FileType.FIFO_SPECIAL;
    } else if (attributes.isSocket()) {
        fileType = FileType.SOCKET_SPECIAL;
    } else if (attributes.isLink()) {
        fileType = FileType.SYMBOLIC_LINK;
    }
    int permissions = attributes.getPermissions().intValue();
    com.jn.agileway.ssh.client.sftp.attrs.FileMode fileMode = FileMode.createFileMode(fileType, permissions);
    attrs.setFileMode(fileMode);
    return attrs;
}
Also used : FileAttrs(com.jn.agileway.ssh.client.sftp.attrs.FileAttrs) FileMode(com.jn.agileway.ssh.client.sftp.attrs.FileMode) FileType(com.jn.agileway.ssh.client.sftp.attrs.FileType)

Example 12 with FileMode

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

the class Ssh2Sftps method fromSsh2FileAttributes.

public static FileAttrs fromSsh2FileAttributes(SFTPv3FileAttributes attributes) {
    if (attributes == null) {
        return null;
    }
    FileAttrs attrs = new FileAttrs();
    if (attributes.size != null) {
        attrs.setSize(attributes.size);
    }
    if (attributes.atime != null) {
        attrs.setAccessTime(attributes.atime.intValue());
    }
    if (attributes.mtime != null) {
        attrs.setModifyTime(attributes.mtime.intValue());
    }
    if (attributes.uid != null) {
        attrs.setUid(attributes.uid);
    }
    if (attributes.gid != null) {
        attrs.setGid(attributes.gid);
    }
    if (attributes.permissions != null) {
        FileMode fileMode = new FileMode(attributes.permissions);
        attrs.setFileMode(fileMode);
    }
    return attrs;
}
Also used : FileAttrs(com.jn.agileway.ssh.client.sftp.attrs.FileAttrs) FileMode(com.jn.agileway.ssh.client.sftp.attrs.FileMode)

Example 13 with FileMode

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

the class FileModeTests method test0.

void test0(FileType fileType, int permissions) {
    FileMode mode = FileMode.createFileMode(fileType, permissions);
    Assert.assertEquals(fileType, mode.getType());
    Assert.assertEquals(permissions, mode.getPermissionsMask());
}
Also used : FileMode(com.jn.agileway.ssh.client.sftp.attrs.FileMode)

Example 14 with FileMode

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

the class SftpFileObject method doSetExecutable.

@Override
protected boolean doSetExecutable(boolean executable, boolean ownerOnly) throws Exception {
    PosixFilePermissions posixFilePermissions = Sftps.getPosixPermission(getSftpSession().open(relPath, OpenMode.READ, null));
    int oldPerm = posixFilePermissions.getPermissions();
    if (executable) {
        posixFilePermissions.addPermission(FilePermission.USR_X);
    } else {
        posixFilePermissions.removePermission(FilePermission.USR_X);
    }
    if (!ownerOnly) {
        posixFilePermissions.addPermission(FilePermission.GRP_X);
        posixFilePermissions.addPermission(FilePermission.OTH_X);
    }
    if (posixFilePermissions.getPermissions() == oldPerm) {
        return true;
    }
    FileMode fileMode = FileMode.createFileMode(getFileAttrs().getFileMode().getType(), posixFilePermissions.getPermissions());
    getFileAttrs().setFileMode(fileMode);
    flushStat();
    return true;
}
Also used : FileMode(com.jn.agileway.ssh.client.sftp.attrs.FileMode) PosixFilePermissions(com.jn.langx.util.io.file.PosixFilePermissions)

Aggregations

FileMode (com.jn.agileway.ssh.client.sftp.attrs.FileMode)14 FileAttrs (com.jn.agileway.ssh.client.sftp.attrs.FileAttrs)6 PosixFilePermissions (com.jn.langx.util.io.file.PosixFilePermissions)3 NoSuchFileSftpException (com.jn.agileway.ssh.client.sftp.exception.NoSuchFileSftpException)2 SFTPv3FileHandle (ch.ethz.ssh2.SFTPv3FileHandle)1 FileType (com.jn.agileway.ssh.client.sftp.attrs.FileType)1 SftpException (com.jn.agileway.ssh.client.sftp.exception.SftpException)1 SftpFileAttributes (com.sshtools.common.sftp.SftpFileAttributes)1 UnsignedInteger32 (com.sshtools.common.util.UnsignedInteger32)1 UnsignedInteger64 (com.sshtools.common.util.UnsignedInteger64)1 SFTPv3FileHandle (com.trilead.ssh2.SFTPv3FileHandle)1