public Builder withType(FileMode.Type type) { mask |= Flag.MODE.get(); this.mode = new FileMode(type.toMask() | (mode != null ? mode.getPermissionsMask() : 0)); return this; }
@Override public void download(String source, LocalDestFile dest) throws IOException { final PathComponents pathComponents = engine.getPathHelper().getComponents(source); final FileAttributes attributes = engine.stat(source); new Downloader().download(getTransferListener(), new RemoteResourceInfo(pathComponents, attributes), dest); }
public PacketType readType() throws SFTPException { try { return PacketType.fromByte(readByte()); } catch (BufferException be) { throw new SFTPException(be); } }
public RemoteFile open(String path, Set<OpenMode> modes, FileAttributes fa) throws IOException { final byte[] handle = doRequest( newRequest(PacketType.OPEN).putString(path, sub.getRemoteCharset()).putUInt32(OpenMode.toMask(modes)).putFileAttributes(fa) ).ensurePacketTypeIs(PacketType.HANDLE).readBytes(); return new RemoteFile(this, path, handle); }
@Override public List<RemoteResourceInfo> ls(String path, RemoteResourceFilter filter) throws IOException { final RemoteDirectory dir = getSFTPEngine().openDir(cwdify(path)); try { return dir.scan(filter); } finally { dir.close(); } }
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"); }
protected Promise<Response, SFTPException> asyncWrite(long fileOffset, byte[] data, int off, int len) throws IOException { return requester.request(newRequest(PacketType.WRITE) .putUInt64(fileOffset) .putString(data, off, len) ); }
public StatusCode readStatusCode() throws SFTPException { try { return StatusCode.fromInt(readUInt32AsInt()); } catch (BufferException be) { throw new SFTPException(be); } }
private void setAttributes(LocalSourceFile local, String remotePath) throws IOException { if (getPreserveAttributes()) { engine.setAttributes(remotePath, getAttributes(local)); } }
protected String error(StatusCode sc) throws SFTPException { try { throw new SFTPException(sc, protocolVersion < 3 ? sc.toString() : readString()); } catch (BufferException be) { throw new SFTPException(be); } }
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 Builder withPermissions(int perms) { mask |= Flag.MODE.get(); this.mode = new FileMode((mode != null ? mode.getTypeMask() : 0) | perms); return this; }
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; } } }
@Override public String canonicalize(String path) throws IOException { return super.canonicalize(cwdify(path)); }