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);
}
if (attributes.mtime != null) {
attrs.setModifyTime(attributes.mtime);
}
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.FileMode 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.FileMode in project agileway by fangjinuo.
the class Ssh2SftpSession method mkdir.
@Override
public void mkdir(String directory, FileAttrs attributes) throws SftpException {
try {
FileMode fileMode = attributes == null ? null : attributes.getFileMode();
int permissions = fileMode == null ? 0775 : fileMode.getMask();
sftpClient.mkdir(directory, permissions);
} catch (Throwable ex) {
throw Ssh2Sftps.wrapSftpException(ex);
}
}
use of com.jn.agileway.ssh.client.sftp.attrs.FileMode 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.FileMode in project agileway by fangjinuo.
the class JschSftps method toSftpATTRS.
public static SftpATTRS toSftpATTRS(@NonNull SftpATTRS sftpATTRS, @Nullable FileAttrs attrs) {
if (attrs == null) {
return sftpATTRS;
}
Long size = attrs.getSize();
if (size != null) {
sftpATTRS.setSIZE(size);
}
Integer uid = attrs.getUid();
Integer gid = attrs.getGid();
if (uid != null || gid != null) {
sftpATTRS.setUIDGID(Objs.useValueIfNull(uid, sftpATTRS.getUId()), Objs.useValueIfNull(gid, sftpATTRS.getGId()));
}
Integer atime = attrs.getAccessTime();
Integer mtime = attrs.getModifyTime();
if (atime != null || mtime != null) {
sftpATTRS.setACMODTIME(Objs.useValueIfNull(atime, sftpATTRS.getATime()), Objs.useValueIfNull(mtime, sftpATTRS.getMTime()));
}
FileMode fileMode = attrs.getFileMode();
if (fileMode != null) {
sftpATTRS.setPERMISSIONS(fileMode.getMask());
}
return sftpATTRS;
}
Aggregations