use of com.jn.agileway.ssh.client.sftp.attrs.FileAttrs in project agileway by fangjinuo.
the class Ssh2SftpSession method open.
@Override
public SftpFile open(String filepath, int openMode, FileAttrs attrs) throws SftpException {
try {
SFTPv3FileHandle handle = null;
if (!Sftps.exists(this, filepath)) {
if (attrs == null) {
attrs = new FileAttrs();
}
FileMode fileMode = attrs.getFileMode();
if (fileMode == null) {
fileMode = FileMode.createFileMode(FileType.REGULAR, 0644);
attrs.setFileMode(fileMode);
}
if (OpenMode.isCreatable(openMode)) {
handle = sftpClient.createFileTruncate(filepath, Ssh2Sftps.toSsh2FileAttributes(attrs));
} else {
throw new NoSuchFileSftpException(StringTemplates.formatWithPlaceholder("no such file: {}", filepath));
}
} else {
if (OpenMode.isTruncated(openMode)) {
handle = sftpClient.createFileTruncate(filepath, Ssh2Sftps.toSsh2FileAttributes(attrs));
}
}
if (handle != null) {
sftpClient.closeFile(handle);
handle = null;
}
if (OpenMode.isWritable(openMode)) {
handle = sftpClient.openFileRW(filepath);
} else {
handle = sftpClient.openFileRO(filepath);
}
Ssh2SftpFile sftpFile = new Ssh2SftpFile(this, filepath);
sftpFile.setFileHandle(handle);
return sftpFile;
} catch (Throwable ex) {
throw new SftpException(ex);
}
}
use of com.jn.agileway.ssh.client.sftp.attrs.FileAttrs in project agileway by fangjinuo.
the class JschSftps method fromSftpATTRS.
public static FileAttrs fromSftpATTRS(SftpATTRS sftpATTRS) {
if (sftpATTRS == null) {
return null;
}
FileAttrs attrs = new FileAttrs();
attrs.setSize(sftpATTRS.getSize());
attrs.setUid(sftpATTRS.getUId());
attrs.setGid(sftpATTRS.getGId());
attrs.setAccessTime(sftpATTRS.getATime());
attrs.setModifyTime(sftpATTRS.getMTime());
FileMode fileMode = new FileMode(sftpATTRS.getPermissions());
attrs.setFileMode(fileMode);
return attrs;
}
use of com.jn.agileway.ssh.client.sftp.attrs.FileAttrs 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;
}
use of com.jn.agileway.ssh.client.sftp.attrs.FileAttrs 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;
}
use of com.jn.agileway.ssh.client.sftp.attrs.FileAttrs in project agileway by fangjinuo.
the class Sftps method chgrp.
public static void chgrp(final SftpSession session, String path, int gid) throws IOException {
FileAttrs attrs = session.stat(path);
FileAttrs attrs2 = new FileAttrs();
attrs2.setUid(attrs.getUid());
attrs2.setGid(gid);
session.setStat(path, attrs2);
}
Aggregations