Example #1
0
  /**
   * @param channel
   * @param bytesToAdd
   * @throws IOException
   */
  public void sendChannelWindowAdjust(Channel channel, long bytesToAdd) throws IOException {
    log.debug("Increasing window size by " + String.valueOf(bytesToAdd) + " bytes");

    SshMsgChannelWindowAdjust msg =
        new SshMsgChannelWindowAdjust(channel.getRemoteChannelId(), bytesToAdd);
    transport.sendMessage(msg, this);
  }
Example #2
0
  /**
   * @param channel
   * @param extendedType
   * @param data
   * @throws IOException
   */
  public synchronized void sendChannelExtData(Channel channel, int extendedType, byte[] data)
      throws IOException {
    channel.getRemoteWindow().consumeWindowSpace(data.length);

    int sent = 0;
    int block;
    int remaining;
    long max;
    byte[] buffer;
    ChannelDataWindow window = channel.getRemoteWindow();

    while (sent < data.length) {
      remaining = data.length - sent;
      max =
          ((window.getWindowSpace() < channel.getRemotePacketSize())
                  && (window.getWindowSpace() > 0))
              ? window.getWindowSpace()
              : channel.getRemotePacketSize();
      block = (max < remaining) ? (int) max : remaining;
      channel.remoteWindow.consumeWindowSpace(block);
      buffer = new byte[block];
      System.arraycopy(data, sent, buffer, 0, block);

      SshMsgChannelExtendedData msg =
          new SshMsgChannelExtendedData(channel.getRemoteChannelId(), extendedType, buffer);
      transport.sendMessage(msg, this);

      /*                if (type != null) {
          channel.sendChannelExtData(type.intValue(), buffer);
      } else {
          channel.sendChannelData(buffer);
      }*/
      sent += block;
    }
  }
Example #3
0
 /**
  * @param channel
  * @throws IOException
  */
 protected void sendChannelOpenConfirmation(Channel channel) throws IOException {
   SshMsgChannelOpenConfirmation msg =
       new SshMsgChannelOpenConfirmation(
           channel.getRemoteChannelId(),
           channel.getLocalChannelId(),
           channel.getLocalWindow().getWindowSpace(),
           channel.getLocalPacketSize(),
           channel.getChannelConfirmationData());
   transport.sendMessage(msg, this);
 }
Example #4
0
 /**
  * @param channel
  * @throws IOException
  */
 protected void closeChannel(Channel channel) throws IOException {
   SshMsgChannelClose msg = new SshMsgChannelClose(channel.getRemoteChannelId());
   log.info(
       "Local computer has closed channel "
           + String.valueOf(channel.getLocalChannelId())
           + "["
           + channel.getName()
           + "]");
   transport.sendMessage(msg, this);
 }
Example #5
0
  /**
   * @param channel
   * @param requestType
   * @param wantReply
   * @param requestData
   * @return
   * @throws IOException
   * @throws SshException
   */
  public synchronized boolean sendChannelRequest(
      Channel channel, String requestType, boolean wantReply, byte[] requestData)
      throws IOException {
    boolean success = true;
    log.debug(
        "Sending " + requestType + " request for the " + channel.getChannelType() + " channel");

    SshMsgChannelRequest msg =
        new SshMsgChannelRequest(channel.getRemoteChannelId(), requestType, wantReply, requestData);
    transport.sendMessage(msg, this);

    // If the user requests a reply then wait for the message and return result
    if (wantReply) {
      // Set up our message filter
      int[] messageIdFilter = new int[2];
      messageIdFilter[0] = SshMsgChannelSuccess.SSH_MSG_CHANNEL_SUCCESS;
      messageIdFilter[1] = SshMsgChannelFailure.SSH_MSG_CHANNEL_FAILURE;
      log.debug("Waiting for channel request reply");

      try {
        // Wait for either success or failure
        SshMessage reply = messageStore.getMessage(messageIdFilter);

        switch (reply.getMessageId()) {
          case SshMsgChannelSuccess.SSH_MSG_CHANNEL_SUCCESS:
            {
              log.debug("Channel request succeeded");
              success = true;

              break;
            }

          case SshMsgChannelFailure.SSH_MSG_CHANNEL_FAILURE:
            {
              log.debug("Channel request failed");
              success = false;

              break;
            }
        }
      } catch (InterruptedException ex) {
        throw new SshException(
            "The thread was interrupted whilst waiting for a connection protocol message");
      }
    }

    return success;
  }
Example #6
0
  /**
   * @param channel
   * @throws IOException
   */
  public void sendChannelEOF(Channel channel) throws IOException {
    synchronized (activeChannels) {
      if (!activeChannels.containsValue(channel)) {
        throw new IOException(
            "Attempt to send EOF for a non existent channel "
                + String.valueOf(channel.getLocalChannelId()));
      }

      log.info(
          "Local computer has set channel "
              + String.valueOf(channel.getLocalChannelId())
              + " to EOF ["
              + channel.getName()
              + "]");

      SshMsgChannelEOF msg = new SshMsgChannelEOF(channel.getRemoteChannelId());
      transport.sendMessage(msg, this);
    }
  }
Example #7
0
  /**
   * @param channel
   * @param data
   * @throws IOException
   */
  public synchronized void sendChannelData(Channel channel, byte[] data) throws IOException {
    synchronized (channel.getState()) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Sending "
                + String.valueOf(data.length)
                + " bytes for channel id "
                + String.valueOf(channel.getLocalChannelId()));
      }

      int sent = 0;
      int block;
      int remaining;
      long max;
      byte[] buffer;
      ChannelDataWindow window = channel.getRemoteWindow();

      while (sent < data.length) {
        remaining = data.length - sent;
        max =
            ((window.getWindowSpace() < channel.getRemotePacketSize())
                    && (window.getWindowSpace() > 0))
                ? window.getWindowSpace()
                : channel.getRemotePacketSize();
        block = (max < remaining) ? (int) max : remaining;
        channel.remoteWindow.consumeWindowSpace(block);
        buffer = new byte[block];
        System.arraycopy(data, sent, buffer, 0, block);

        SshMsgChannelData msg = new SshMsgChannelData(channel.getRemoteChannelId(), buffer);
        transport.sendMessage(msg, this);

        /*                if (type != null) {
        channel.sendChannelExtData(type.intValue(), buffer);
                   } else {
                       channel.sendChannelData(buffer);
                   }*/
        sent += block;
      }
    }
  }
Example #8
0
 /**
  * @param channel
  * @throws IOException
  */
 protected void sendChannelFailure(Channel channel) throws IOException {
   SshMsgChannelFailure msg = new SshMsgChannelFailure(channel.getRemoteChannelId());
   transport.sendMessage(msg, this);
 }
Example #9
0
 /**
  * @param channel
  * @throws IOException
  */
 public void sendChannelRequestSuccess(Channel channel) throws IOException {
   SshMsgChannelSuccess msg = new SshMsgChannelSuccess(channel.getRemoteChannelId());
   transport.sendMessage(msg, this);
 }