@Override public SFTPException chain(Throwable t) { if (t instanceof SFTPException) return (SFTPException) t; else return new SFTPException(t); }
public FileAttributes statExistence(String path) throws IOException { try { return engine.stat(path); } catch (SFTPException sftpe) { if (sftpe.getStatusCode() == Response.StatusCode.NO_SUCH_FILE) { return null; } else { throw sftpe; } } }
private void readIntoBuffer(byte[] buf, int off, int len) throws IOException { int count = 0; int read = 0; while (count < len && ((read = in.read(buf, off + count, len - count)) != -1)) count += read; if (read == -1) throw new SFTPException("EOF while reading packet"); }
private boolean isDirectory(final String remote) throws IOException { try { FileAttributes attrs = engine.stat(remote); return attrs.getMode().getType() == FileMode.Type.DIRECTORY; } catch (SFTPException e) { if (e.getStatusCode() == StatusCode.NO_SUCH_FILE) { log.debug("isDir: {} does not exist", remote); return false; } else { throw e; } } }
protected String error(StatusCode sc) throws SFTPException { try { throw new SFTPException(sc, protocolVersion < 3 ? sc.toString() : readString()); } catch (BufferException be) { throw new SFTPException(be); } }
private String prepareFile(final LocalSourceFile local, final String remote) throws IOException { final FileAttributes attrs; try { attrs = engine.stat(remote); } catch (SFTPException e) { if (e.getStatusCode() == StatusCode.NO_SUCH_FILE) { log.debug("probeFile: {} does not exist", remote); return remote; } else throw e; } if (attrs.getMode().getType() == FileMode.Type.DIRECTORY) { throw new IOException("Trying to upload file " + local.getName() + " to path " + remote + " but that is a directory"); } else { log.debug("probeFile: {} is a {} file that will be replaced", remote, attrs.getMode().getType()); return remote; } }
public synchronized void cd(String dirname) throws IOException { final String targetCwd = cwdify(dirname); if (statExistence(targetCwd) == null) { throw new SFTPException(targetCwd + ": does not exist"); } cwd = targetCwd; log.debug("CWD = {}", cwd); }
private boolean makeDirIfNotExists(final String remote) throws IOException { try { FileAttributes attrs = engine.stat(remote); if (attrs.getMode().getType() != FileMode.Type.DIRECTORY) { throw new IOException(remote + " exists and should be a directory, but was a " + attrs.getMode().getType()); } // Was not created, but existed. return false; } catch (SFTPException e) { if (e.getStatusCode() == StatusCode.NO_SUCH_FILE) { log.debug("makeDir: {} does not exist, creating", remote); engine.makeDir(remote); return true; } else { throw e; } } }
public PacketType readType() throws SFTPException { try { return PacketType.fromByte(readByte()); } catch (BufferException be) { throw new SFTPException(be); } }
public FileAttributes statExistence(String path) throws IOException { try { return engine.stat(path); } catch (SFTPException sftpe) { if (sftpe.getStatusCode() == Response.StatusCode.NO_SUCH_FILE) { return null; } else { throw sftpe; } } }
public Response(Buffer<Response> pk, int protocolVersion) throws SFTPException { super(pk); this.protocolVersion = protocolVersion; this.type = readType(); try { this.reqID = readUInt32(); } catch (BufferException be) { throw new SFTPException(be); } }
public FileAttributes statExistence(String path) throws IOException { try { return engine.stat(path); } catch (SFTPException sftpe) { if (sftpe.getStatusCode() == Response.StatusCode.NO_SUCH_FILE) { return null; } else { throw sftpe; } } }
public StatusCode readStatusCode() throws SFTPException { try { return StatusCode.fromInt(readUInt32AsInt()); } catch (BufferException be) { throw new SFTPException(be); } }
private boolean isDirectory(final String remote) throws IOException { try { FileAttributes attrs = engine.stat(remote); return attrs.getMode().getType() == FileMode.Type.DIRECTORY; } catch (SFTPException e) { if (e.getStatusCode() == StatusCode.NO_SUCH_FILE) { log.debug("isDir: {} does not exist", remote); return false; } else { throw e; } } }
throw new SFTPException("Unexpected response size (0), bailing out");
private String prepareFile(final LocalSourceFile local, final String remote) throws IOException { final FileAttributes attrs; try { attrs = engine.stat(remote); } catch (SFTPException e) { if (e.getStatusCode() == StatusCode.NO_SUCH_FILE) { log.debug("probeFile: {} does not exist", remote); return remote; } else throw e; } if (attrs.getMode().getType() == FileMode.Type.DIRECTORY) { throw new IOException("Trying to upload file " + local.getName() + " to path " + remote + " but that is a directory"); } else { log.debug("probeFile: {} is a {} file that will be replaced", remote, attrs.getMode().getType()); return remote; } }
public void handle() throws SFTPException { Response resp = new Response(packet, engine.getOperativeProtocolVersion()); Promise<Response, SFTPException> promise = promises.remove(resp.getRequestID()); log.debug("Received {} packet", resp.getType()); if (promise == null) throw new SFTPException("Received [" + resp.readType() + "] response for request-id " + resp.getRequestID() + ", no such request was made"); else promise.deliver(resp); }
private boolean makeDirIfNotExists(final String remote) throws IOException { try { FileAttributes attrs = engine.stat(remote); if (attrs.getMode().getType() != FileMode.Type.DIRECTORY) { throw new IOException(remote + " exists and should be a directory, but was a " + attrs.getMode().getType()); } // Was not created, but existed. return false; } catch (SFTPException e) { if (e.getStatusCode() == StatusCode.NO_SUCH_FILE) { log.debug("makeDir: {} does not exist, creating", remote); engine.makeDir(remote); return true; } else { throw e; } } }
private static byte[] readSingleNameAsBytes(Response res) throws IOException { res.ensurePacketTypeIs(PacketType.NAME); if (res.readUInt32AsInt() == 1) return res.readStringAsBytes(); else throw new SFTPException("Unexpected data in " + res.getType() + " packet"); }
private String prepareFile(final LocalSourceFile local, final String remote) throws IOException { final FileAttributes attrs; try { attrs = engine.stat(remote); } catch (SFTPException e) { if (e.getStatusCode() == StatusCode.NO_SUCH_FILE) { log.debug("probeFile: {} does not exist", remote); return remote; } else throw e; } if (attrs.getMode().getType() == FileMode.Type.DIRECTORY) { log.debug("probeFile: {} was directory, path adjusted for {}", remote, local.getName()); return engine.getPathHelper().adjustForParent(remote, local.getName()); } else { log.debug("probeFile: {} is a {} file that will be replaced", remote, attrs.getMode().getType()); return remote; } }