use of com.jn.agileway.ssh.client.sftp.exception.NoSuchFileSftpException 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 Ssh2Sftps.wrapSftpException(ex);
}
}
use of com.jn.agileway.ssh.client.sftp.exception.NoSuchFileSftpException 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.exception.NoSuchFileSftpException in project agileway by fangjinuo.
the class JschSftps method wrapSftpException.
public static SftpException wrapSftpException(com.jcraft.jsch.SftpException ex) {
ResponseStatusCode statusCode = Enums.ofCode(ResponseStatusCode.class, ex.id);
SftpException exception = null;
if (statusCode == ResponseStatusCode.NO_SUCH_FILE) {
exception = new NoSuchFileSftpException(ex);
} else {
exception = new SftpException(ex);
}
exception.setStatusCode(statusCode);
return exception;
}
use of com.jn.agileway.ssh.client.sftp.exception.NoSuchFileSftpException in project agileway by fangjinuo.
the class Ssh2Sftps method wrapSftpException.
public static SftpException wrapSftpException(Throwable ex) {
if (ex instanceof SFTPException) {
ResponseStatusCode statusCode = Enums.ofCode(ResponseStatusCode.class, ((SFTPException) ex).getServerErrorCode());
SftpException exception = null;
if (statusCode == ResponseStatusCode.NO_SUCH_FILE) {
exception = new NoSuchFileSftpException(ex);
} else {
exception = new SftpException(ex);
}
exception.setStatusCode(statusCode);
return exception;
} else {
return new SftpException(ex);
}
}
use of com.jn.agileway.ssh.client.sftp.exception.NoSuchFileSftpException in project agileway by fangjinuo.
the class SshjSftps method wrapSftpException.
public static SftpException wrapSftpException(Throwable ex) {
if (ex instanceof SFTPException) {
ResponseStatusCode statusCode = Enums.ofName(ResponseStatusCode.class, ((SFTPException) ex).getStatusCode().name());
SftpException exception = null;
if (statusCode == ResponseStatusCode.NO_SUCH_FILE) {
exception = new NoSuchFileSftpException(ex);
} else {
exception = new SftpException(ex);
}
exception.setStatusCode(statusCode);
return exception;
} else {
return new SftpException(ex);
}
}
Aggregations