public SFTPPacket<Response> readPacket() throws IOException { final int len = getPacketLength(); packet.clear(); packet.ensureCapacity(len); readIntoBuffer(packet.array(), 0, len); packet.wpos(len); return packet; }
public SFTPEngine init() throws IOException { transmit(new SFTPPacket<Request>(PacketType.INIT).putUInt32(MAX_SUPPORTED_VERSION)); final SFTPPacket<Response> response = reader.readPacket(); final PacketType type = response.readType(); if (type != PacketType.VERSION) throw new SFTPException("Expected INIT packet, received: " + type); operativeVersion = response.readUInt32AsInt(); log.debug("Server version {}", operativeVersion); if (MAX_SUPPORTED_VERSION < operativeVersion) throw new SFTPException("Server reported incompatible protocol version: " + operativeVersion); while (response.available() > 0) serverExtensions.put(response.readString(), response.readString()); // Start reader thread reader.start(); return this; }
public SFTPPacket(PacketType pt) { super(); putByte(pt.toByte()); }
protected synchronized void transmit(SFTPPacket<Request> payload) throws IOException { final int len = payload.available(); out.write((len >>> 24) & 0xff); out.write((len >>> 16) & 0xff); out.write((len >>> 8) & 0xff); out.write(len & 0xff); out.write(payload.array(), payload.rpos(), len); out.flush(); }
public FileAttributes readFileAttributes() throws SFTPException { final FileAttributes.Builder builder = new FileAttributes.Builder(); try { final int mask = readUInt32AsInt(); if (FileAttributes.Flag.SIZE.isSet(mask)) builder.withSize(readUInt64()); if (FileAttributes.Flag.UIDGID.isSet(mask)) builder.withUIDGID(readUInt32AsInt(), readUInt32AsInt()); if (FileAttributes.Flag.MODE.isSet(mask)) builder.withPermissions(readUInt32AsInt()); if (FileAttributes.Flag.ACMODTIME.isSet(mask)) builder.withAtimeMtime(readUInt32AsInt(), readUInt32AsInt()); if (FileAttributes.Flag.EXTENDED.isSet(mask)) { final int extCount = readUInt32AsInt(); for (int i = 0; i < extCount; i++) builder.withExtended(readString(), readString()); } } catch (BufferException be) { throw new SFTPException(be); } return builder.build(); }
@Test public void shouldReadPacket() throws Exception { byte[] bytes = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; dataout.writeInt(10); dataout.write(bytes); dataout.flush(); SFTPPacket<Response> packet = reader.readPacket(); assertEquals(packet.available(), 10); assertTrue("actual=" + Arrays.toString(packet.array()), Arrays.equals(bytes, subArray(packet.array(), 0, 10))); }
public PacketType readType() throws SFTPException { try { return PacketType.fromByte(readByte()); } catch (BufferException be) { throw new SFTPException(be); } }
public T putFileAttributes(FileAttributes fa) { return putRawBytes(fa.toBytes()); }
protected synchronized void transmit(SFTPPacket<Request> payload) throws IOException { final int len = payload.available(); out.write((len >>> 24) & 0xff); out.write((len >>> 16) & 0xff); out.write((len >>> 8) & 0xff); out.write(len & 0xff); out.write(payload.array(), payload.rpos(), len); out.flush(); }
public FileAttributes readFileAttributes() throws SFTPException { final FileAttributes.Builder builder = new FileAttributes.Builder(); try { final int mask = readUInt32AsInt(); if (FileAttributes.Flag.SIZE.isSet(mask)) builder.withSize(readUInt64()); if (FileAttributes.Flag.UIDGID.isSet(mask)) builder.withUIDGID(readUInt32AsInt(), readUInt32AsInt()); if (FileAttributes.Flag.MODE.isSet(mask)) builder.withPermissions(readUInt32AsInt()); if (FileAttributes.Flag.ACMODTIME.isSet(mask)) builder.withAtimeMtime(readUInt32AsInt(), readUInt32AsInt()); if (FileAttributes.Flag.EXTENDED.isSet(mask)) { final int extCount = readUInt32AsInt(); for (int i = 0; i < extCount; i++) builder.withExtended(readString(), readString()); } } catch (BufferException be) { throw new SFTPException(be); } return builder.build(); }
public PacketType readType() throws SFTPException { try { return PacketType.fromByte(readByte()); } catch (BufferException be) { throw new SFTPException(be); } }
public T putFileAttributes(FileAttributes fa) { return putRawBytes(fa.toBytes()); }
public SFTPEngine init() throws IOException { transmit(new SFTPPacket<Request>(PacketType.INIT).putUInt32(MAX_SUPPORTED_VERSION)); final SFTPPacket<Response> response = reader.readPacket(); final PacketType type = response.readType(); if (type != PacketType.VERSION) throw new SFTPException("Expected INIT packet, received: " + type); operativeVersion = response.readUInt32AsInt(); log.debug("Server version {}", operativeVersion); if (MAX_SUPPORTED_VERSION < operativeVersion) throw new SFTPException("Server reported incompatible protocol version: " + operativeVersion); while (response.available() > 0) serverExtensions.put(response.readString(), response.readString()); // Start reader thread reader.start(); return this; }
public SFTPPacket<Response> readPacket() throws IOException { final int len = getPacketLength(); packet.clear(); packet.ensureCapacity(len); readIntoBuffer(packet.array(), 0, len); packet.wpos(len); return packet; }
protected synchronized void transmit(SFTPPacket<Request> payload) throws IOException { final int len = payload.available(); out.write((len >>> 24) & 0xff); out.write((len >>> 16) & 0xff); out.write((len >>> 8) & 0xff); out.write(len & 0xff); out.write(payload.array(), payload.rpos(), len); out.flush(); }
public FileAttributes readFileAttributes() throws SFTPException { final FileAttributes.Builder builder = new FileAttributes.Builder(); try { final int mask = readUInt32AsInt(); if (FileAttributes.Flag.SIZE.isSet(mask)) builder.withSize(readUInt64()); if (FileAttributes.Flag.UIDGID.isSet(mask)) builder.withUIDGID(readUInt32AsInt(), readUInt32AsInt()); if (FileAttributes.Flag.MODE.isSet(mask)) builder.withPermissions(readUInt32AsInt()); if (FileAttributes.Flag.ACMODTIME.isSet(mask)) builder.withAtimeMtime(readUInt32AsInt(), readUInt32AsInt()); if (FileAttributes.Flag.EXTENDED.isSet(mask)) { final int extCount = readUInt32AsInt(); for (int i = 0; i < extCount; i++) builder.withExtended(readString(), readString()); } } catch (BufferException be) { throw new SFTPException(be); } return builder.build(); }
public T putType(PacketType type) { return putByte(type.toByte()); }
public PacketType readType() throws SFTPException { try { return PacketType.fromByte(readByte()); } catch (BufferException be) { throw new SFTPException(be); } }
public T putFileAttributes(FileAttributes fa) { return putRawBytes(fa.toBytes()); }
public SFTPEngine init() throws IOException { transmit(new SFTPPacket<Request>(PacketType.INIT).putUInt32(MAX_SUPPORTED_VERSION)); final SFTPPacket<Response> response = reader.readPacket(); final PacketType type = response.readType(); if (type != PacketType.VERSION) throw new SFTPException("Expected INIT packet, received: " + type); operativeVersion = response.readUInt32AsInt(); log.debug("Server version {}", operativeVersion); if (MAX_SUPPORTED_VERSION < operativeVersion) throw new SFTPException("Server reported incompatible protocol version: " + operativeVersion); while (response.available() > 0) serverExtensions.put(response.readString(), response.readString()); // Start reader thread reader.start(); return this; }