Package com.trilead.ssh2.packets

Examples of com.trilead.ssh2.packets.TypesWriter


   */
  public void mkdir(String dirName, int posixPermissions) throws IOException
  {
    int req_id = generateNextRequestID();

    TypesWriter tw = new TypesWriter();
    tw.writeString(dirName, charsetName);
    tw.writeUINT32(AttribFlags.SSH_FILEXFER_ATTR_PERMISSIONS);
    tw.writeUINT32(posixPermissions);

    sendMessage(Packet.SSH_FXP_MKDIR, req_id, tw.getBytes());

    expectStatusOKMessage(req_id);
  }
View Full Code Here


   */
  public void rm(String fileName) throws IOException
  {
    int req_id = generateNextRequestID();

    TypesWriter tw = new TypesWriter();
    tw.writeString(fileName, charsetName);

    sendMessage(Packet.SSH_FXP_REMOVE, req_id, tw.getBytes());

    expectStatusOKMessage(req_id);
  }
View Full Code Here

   */
  public void rmdir(String dirName) throws IOException
  {
    int req_id = generateNextRequestID();

    TypesWriter tw = new TypesWriter();
    tw.writeString(dirName, charsetName);

    sendMessage(Packet.SSH_FXP_RMDIR, req_id, tw.getBytes());

    expectStatusOKMessage(req_id);
  }
View Full Code Here

   */
  public void mv(String oldPath, String newPath) throws IOException
  {
    int req_id = generateNextRequestID();

    TypesWriter tw = new TypesWriter();
    tw.writeString(oldPath, charsetName);
    tw.writeString(newPath, charsetName);

    sendMessage(Packet.SSH_FXP_RENAME, req_id, tw.getBytes());

    expectStatusOKMessage(req_id);
  }
View Full Code Here

    return openFile(fileName, SSH_FXF_CREAT | SSH_FXF_TRUNC | SSH_FXF_WRITE, attr);
  }

  private byte[] createAttrs(SFTPv3FileAttributes attr)
  {
    TypesWriter tw = new TypesWriter();

    int attrFlags = 0;

    if (attr == null)
    {
      tw.writeUINT32(0);
    }
    else
    {
      if (attr.size != null)
      {
        attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_SIZE;
      }

      if ((attr.uid != null) && (attr.gid != null))
      {
        attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_V3_UIDGID;
      }

      if (attr.permissions != null)
      {
        attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_PERMISSIONS;
      }

      if ((attr.atime != null) && (attr.mtime != null))
      {
        attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_V3_ACMODTIME;
      }

      tw.writeUINT32(attrFlags);

      if (attr.size != null)
      {
        tw.writeUINT64(attr.size);
      }

      if ((attr.uid != null) && (attr.gid != null))
      {
        tw.writeUINT32(attr.uid);
        tw.writeUINT32(attr.gid);
      }

      if (attr.permissions != null)
      {
        tw.writeUINT32(attr.permissions);
      }

      if ((attr.atime != null) && (attr.mtime != null))
      {
        tw.writeUINT32(attr.atime);
        tw.writeUINT32(attr.mtime);
      }
    }

    return tw.getBytes();
  }
View Full Code Here

  public SFTPv3FileHandle openFile(String fileName, int flags, SFTPv3FileAttributes attr) throws IOException
  {
    int req_id = generateNextRequestID();

    TypesWriter tw = new TypesWriter();
    tw.writeString(fileName, charsetName);
    tw.writeUINT32(flags);
    tw.writeBytes(createAttrs(attr));

    log.debug("Sending SSH_FXP_OPEN...");
    sendMessage(Packet.SSH_FXP_OPEN, req_id, tw.getBytes());

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);
View Full Code Here

    byte[] buffer;
  }

  private void sendReadRequest(int id, SFTPv3FileHandle handle, long offset, int len) throws IOException
  {
    TypesWriter tw = new TypesWriter();
    tw.writeString(handle.fileHandle, 0, handle.fileHandle.length);
    tw.writeUINT64(offset);
    tw.writeUINT32(len);

    log.debug("Sending SSH_FXP_READ (" + id + ") " + offset + "/" + len);
    sendMessage(Packet.SSH_FXP_READ, id, tw.getBytes());
  }
View Full Code Here

            // Send the next write request
            OutstandingStatusRequest req = new OutstandingStatusRequest();
            req.req_id = generateNextRequestID();

            TypesWriter tw = new TypesWriter();
            tw.writeString(handle.fileHandle, 0, handle.fileHandle.length);
            tw.writeUINT64(fileOffset);
            tw.writeString(src, srcoff, writeRequestLen);

            log.debug("Sending SSH_FXP_WRITE...");
            sendMessage(Packet.SSH_FXP_WRITE, req.req_id, tw.getBytes());

            pendingStatusQueue.put(req.req_id, req);

            // Only read next status if parallelism reached
            while (pendingStatusQueue.size() >= parallelism)
View Full Code Here

    byte[] pubKeyBlob = identity.getPublicKeyBlob();
    if(pubKeyBlob == null) {
      return false;
    }

    TypesWriter tw = new TypesWriter();
    byte[] H = tm.getSessionIdentifier();

    tw.writeString(H, 0, H.length);
    tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
    tw.writeString(user);
    tw.writeString("ssh-connection");
    tw.writeString("publickey");
    tw.writeBoolean(true);
    tw.writeString(identity.getAlgName());
    tw.writeString(pubKeyBlob, 0, pubKeyBlob.length);

    byte[] msg = tw.getBytes();
    byte[] response = identity.sign(msg);

    PacketUserauthRequestPublicKey ua = new PacketUserauthRequestPublicKey(
        "ssh-connection", user, identity.getAlgName(), pubKeyBlob, response);
    tm.sendMessage(ua.getPayload());
View Full Code Here

      {
        DSAPrivateKey pk = (DSAPrivateKey) key;

        byte[] pk_enc = DSASHA1Verify.encodeSSHDSAPublicKey(pk.getPublicKey());

        TypesWriter tw = new TypesWriter();

        byte[] H = tm.getSessionIdentifier();

        tw.writeString(H, 0, H.length);
        tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
        tw.writeString(user);
        tw.writeString("ssh-connection");
        tw.writeString("publickey");
        tw.writeBoolean(true);
        tw.writeString("ssh-dss");
        tw.writeString(pk_enc, 0, pk_enc.length);

        byte[] msg = tw.getBytes();

        DSASignature ds = DSASHA1Verify.generateSignature(msg, pk, rnd);

        byte[] ds_enc = DSASHA1Verify.encodeSSHDSASignature(ds);

        PacketUserauthRequestPublicKey ua = new PacketUserauthRequestPublicKey("ssh-connection", user,
            "ssh-dss", pk_enc, ds_enc);
        tm.sendMessage(ua.getPayload());
      }
      else if (key instanceof RSAPrivateKey)
      {
        RSAPrivateKey pk = (RSAPrivateKey) key;

        byte[] pk_enc = RSASHA1Verify.encodeSSHRSAPublicKey(pk.getPublicKey());

        TypesWriter tw = new TypesWriter();
        {
          byte[] H = tm.getSessionIdentifier();

          tw.writeString(H, 0, H.length);
          tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
          tw.writeString(user);
          tw.writeString("ssh-connection");
          tw.writeString("publickey");
          tw.writeBoolean(true);
          tw.writeString("ssh-rsa");
          tw.writeString(pk_enc, 0, pk_enc.length);
        }

        byte[] msg = tw.getBytes();

        RSASignature ds = RSASHA1Verify.generateSignature(msg, pk);

        byte[] rsa_sig_enc = RSASHA1Verify.encodeSSHRSASignature(ds);
View Full Code Here

TOP

Related Classes of com.trilead.ssh2.packets.TypesWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.