use of com.sshtools.common.sftp.SftpFileAttributes in project agileway by fangjinuo.
the class SynergySftps method toSftpFileAttributes.
public static SftpFileAttributes toSftpFileAttributes(FileAttrs attrs, String encoding) {
int fileType = SftpFileAttributes.SSH_FILEXFER_TYPE_UNKNOWN;
switch(attrs.getFileType()) {
case REGULAR:
fileType = SftpFileAttributes.SSH_FILEXFER_TYPE_REGULAR;
break;
case DIRECTORY:
fileType = SftpFileAttributes.SSH_FILEXFER_TYPE_DIRECTORY;
break;
case SYMBOLIC_LINK:
fileType = SftpFileAttributes.SSH_FILEXFER_TYPE_SYMLINK;
break;
case FIFO_SPECIAL:
fileType = SftpFileAttributes.SSH_FILEXFER_TYPE_FIFO;
break;
case BLOCK_SPECIAL:
fileType = SftpFileAttributes.SSH_FILEXFER_TYPE_BLOCK_DEVICE;
break;
case CHAR_SPECIAL:
fileType = SftpFileAttributes.SSH_FILEXFER_TYPE_CHAR_DEVICE;
break;
case SOCKET_SPECIAL:
fileType = SftpFileAttributes.SSH_FILEXFER_TYPE_SOCKET;
break;
default:
break;
}
SftpFileAttributes attributes = new SftpFileAttributes(fileType, encoding);
if (attrs.getSize() != null) {
attributes.setSize(new UnsignedInteger64(attrs.getSize()));
}
UnsignedInteger64 atime = null;
UnsignedInteger64 mtime = null;
if (attrs.getAccessTime() != null) {
atime = new UnsignedInteger64(attrs.getAccessTime());
}
if (attrs.getModifyTime() != null) {
mtime = new UnsignedInteger64(attrs.getModifyTime());
}
attributes.setTimes(atime, mtime);
if (attrs.getGid() != null) {
attributes.setGID(attrs.getGid().toString());
}
if (attrs.getUid() != null) {
attributes.setUID(attrs.getUid().toString());
}
FileMode fileMode = attrs.getFileMode();
attributes.setPermissions(new UnsignedInteger32(fileMode.getPermissionsMask()));
return attributes;
}
Aggregations