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, 0x00000018 | 0x00000003, attr); // SSH_FXF_CREAT | SSH_FXF_TRUNC | SSH_FXF_READ | SSH_FXF_WRITE
  }

  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.longValue());

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

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

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

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

  private 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));

    if (debug != null)
    {
      debug.println("Sending SSH_FXP_OPEN...");
      debug.flush();
    }

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

    byte[] resp = receiveMessage(34000);

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

    if ((len > 32768) || (len <= 0))
      throw new IllegalArgumentException("invalid len argument");

    int req_id = generateNextRequestID();

    TypesWriter tw = new TypesWriter();
    tw.writeString(handle.fileHandle, 0, handle.fileHandle.length);
    tw.writeUINT64(fileOffset);
    tw.writeUINT32(len);

    if (debug != null)
    {
      debug.println("Sending SSH_FXP_READ...");
      debug.flush();
    }

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

    byte[] resp = receiveMessage(34000);

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

      if (writeRequestLen > 32768)
        writeRequestLen = 32768;

      int req_id = generateNextRequestID();

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

      if (debug != null)
      {
        debug.println("Sending SSH_FXP_WRITE...");
        debug.flush();
      }

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

      fileOffset += writeRequestLen;

      srcoff += writeRequestLen;
      len -= writeRequestLen;
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

    return new RSAPublicKey(e, n);
  }

  public static byte[] encodeSSHRSAPublicKey(RSAPublicKey pk) throws IOException
  {
    TypesWriter tw = new TypesWriter();

    tw.writeString("ssh-rsa");
    tw.writeMPInt(pk.getE());
    tw.writeMPInt(pk.getN());

    return tw.getBytes();
  }
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.