Package com.trilead.ssh2.packets

Examples of com.trilead.ssh2.packets.TypesReader


    log.debug("Sending SSH_FXP_STAT/SSH_FXP_LSTAT...");
    sendMessage(statMethod, req_id, tw.getBytes());

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
    {
      throw new IOException("The server sent an invalid id field.");
    }

    if (t == Packet.SSH_FXP_ATTRS)
    {
      return readAttrs(tr);
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");
    }

    int errorCode = tr.readUINT32();
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here


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

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
    {
      throw new IOException("The server sent an invalid id field.");
    }

    if (t == Packet.SSH_FXP_NAME)
    {
      int count = tr.readUINT32();

      if (count != 1)
      {
        throw new IOException("The server sent an invalid SSH_FXP_NAME packet.");
      }

      return tr.readString(charsetName);
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");
    }

    int errorCode = tr.readUINT32();
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here

  private void expectStatusOKMessage(int id) throws IOException
  {
    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != id)
    {
      throw new IOException("The server sent an invalid id field.");
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");
    }

    int errorCode = tr.readUINT32();

    if (errorCode == ErrorCodes.SSH_FX_OK)
    {
      return;
    }
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here

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

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
    {
      throw new IOException("The server sent an invalid id field.");
    }

    if (t == Packet.SSH_FXP_NAME)
    {
      int count = tr.readUINT32();

      if (count != 1)
      {
        throw new IOException("The server sent an invalid SSH_FXP_NAME packet.");
      }

      final String name = tr.readString(charsetName);
      listener.read(name);
      return name;
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");
    }

    int errorCode = tr.readUINT32();
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here

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

      byte[] resp = receiveMessage(34000);

      TypesReader tr = new TypesReader(resp);

      int t = tr.readByte();
      listener.read(Packet.forName(t));

      int rep_id = tr.readUINT32();
      if (rep_id != req_id)
      {
        throw new IOException("The server sent an invalid id field.");
      }

      if (t == Packet.SSH_FXP_NAME)
      {
        int count = tr.readUINT32();

        log.debug("Parsing " + count + " name entries...");
        while (count > 0)
        {
          SFTPv3DirectoryEntry dirEnt = new SFTPv3DirectoryEntry();

          dirEnt.filename = tr.readString(charsetName);
          dirEnt.longEntry = tr.readString(charsetName);
          listener.read(dirEnt.longEntry);

          dirEnt.attributes = readAttrs(tr);
          files.add(dirEnt);

          log.debug("File: '" + dirEnt.filename + "'");
          count--;
        }
        continue;
      }

      if (t != Packet.SSH_FXP_STATUS)
      {
        throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");
      }

      int errorCode = tr.readUINT32();

      if (errorCode == ErrorCodes.SSH_FX_EOF)
      {
        return files;
      }
      String errorMessage = tr.readString();
      listener.read(errorMessage);
      throw new SFTPException(errorMessage, errorCode);
    }
  }
View Full Code Here

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

    byte[] resp = receiveMessage(34000);

    TypesReader tr = new TypesReader(resp);

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    int rep_id = tr.readUINT32();
    if (rep_id != req_id)
    {
      throw new IOException("The server sent an invalid id field.");
    }

    if (t == Packet.SSH_FXP_HANDLE)
    {
      log.debug("Got SSH_FXP_HANDLE.");
      return new SFTPv3FileHandle(this, tr.readByteString());
    }

    if (t != Packet.SSH_FXP_STATUS)
    {
      throw new IOException("The SFTP server sent an unexpected packet type (" + t + ")");
    }

    int errorCode = tr.readUINT32();
    String errorMessage = tr.readString();
    listener.read(errorMessage);
    throw new SFTPException(errorMessage, errorCode);
  }
View Full Code Here

    sendMessage(Packet.SSH_FXP_INIT, 0, tw.getBytes());

    /* Receive SSH_FXP_VERSION */

    log.debug("Waiting for SSH_FXP_VERSION...");
    TypesReader tr = new TypesReader(receiveMessage(34000)); /* Should be enough for any reasonable server */

    int t = tr.readByte();
    listener.read(Packet.forName(t));

    if (t != Packet.SSH_FXP_VERSION)
    {
      throw new IOException("The server did not send a SSH_FXP_VERSION packet (got " + t + ")");
    }

    protocol_version = tr.readUINT32();

    log.debug("SSH_FXP_VERSION: protocol_version = " + protocol_version);
    if (protocol_version != 3)
    {
      throw new IOException("Server version " + protocol_version + " is currently not supported");
    }

    /* Read and save extensions (if any) for later use */

    while (tr.remain() != 0)
    {
      String name = tr.readString();
      listener.read(name);
      byte[] value = tr.readByteString();
      log.debug("SSH_FXP_VERSION: extension: " + name + " = '" + expandString(value, 0, value.length) + "'");
    }
  }
View Full Code Here

  public void msgGlobalRequest(byte[] msg, int msglen) throws IOException
  {
    /* Currently we do not support any kind of global request */

    TypesReader tr = new TypesReader(msg, 0, msglen);

    tr.readByte(); // skip packet type
    String requestName = tr.readString();
    boolean wantReply = tr.readBoolean();

    if (wantReply)
    {
      byte[] reply_failure = new byte[1];
      reply_failure[0] = Packets.SSH_MSG_REQUEST_FAILURE;
View Full Code Here

      if (type == Packets.SSH_MSG_DEBUG)
      {
        if (log.isDebugEnabled())
        {
          TypesReader tr = new TypesReader(msg, 0, msglen);
          tr.readByte();
          tr.readBoolean();
          StringBuilder debugMessageBuffer = new StringBuilder();
          debugMessageBuffer.append(tr.readString("UTF-8"));

          for (int i = 0; i < debugMessageBuffer.length(); i++)
          {
            char c = debugMessageBuffer.charAt(i);

            if ((c >= 32) && (c <= 126))
            {
              continue;
            }
            debugMessageBuffer.setCharAt(i, '\uFFFD');
          }

          log.debug("DEBUG Message from remote: '" + debugMessageBuffer.toString() + "'");
        }
        continue;
      }

      if (type == Packets.SSH_MSG_UNIMPLEMENTED)
      {
        throw new IOException("Peer sent UNIMPLEMENTED message, that should not happen.");
      }

      if (type == Packets.SSH_MSG_DISCONNECT)
      {
        TypesReader tr = new TypesReader(msg, 0, msglen);
        tr.readByte();
        int reason_code = tr.readUINT32();
        StringBuilder reasonBuffer = new StringBuilder();
        reasonBuffer.append(tr.readString("UTF-8"));

        /*
         * Do not get fooled by servers that send abnormal long error
         * messages
         */
 
View Full Code Here

   */
  protected Connection getBaseAuthentication() throws Exception {

    try { // to connect and authenticate
      boolean isAuthenticated = false;
      this.setSshConnection(new Connection(this.host, this.port));

      if (proxyHost != null && this.proxyHost.length() > 0) {
        if (this.proxyUser != null && this.proxyUser.length() > 0) {
          this.getSshConnection().setProxyData(new HTTPProxyData(this.proxyHost, this.proxyPort));
        }
View Full Code Here

TOP

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

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.