# RemotePortForwarder (sshj 0.4.0 API)
Date: 2011-06-06

## net.schmizz.sshj.connection.channel.forwarded
Class RemotePortForwarder

    java.lang.Object
      net.schmizz.sshj.connection.channel.forwarded.AbstractForwardedChannelOpener
          net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder

All Implemented Interfaces:
  ForwardedChannelOpener

    public class RemotePortForwarder

extends AbstractForwardedChannelOpener

Handles remote port forwarding.

Nested Class Summary
`static class` `RemotePortForwarder.Forward` Represents a particular forwarding.
`static class` `RemotePortForwarder.ForwardedTCPIPChannel` A `forwarded-tcpip` channel.

Field Summary
`protected Map<RemotePortForwarder.Forward,ConnectListener>` `listeners`
`protected static String` `PF_CANCEL`
`protected static String` `PF_REQ`

Fields inherited from class net.schmizz.sshj.connection.channel.forwarded.AbstractForwardedChannelOpener
`chanType, conn, log`

Constructor Summary
`RemotePortForwarder(Connection conn)`

Method Summary
`RemotePortForwarder.Forward` `bind(RemotePortForwarder.Forward forward, ConnectListener listener)` Request forwarding from the remote host on the specified `RemotePortForwarder.Forward`.
`void` `cancel(RemotePortForwarder.Forward forward)` Request cancellation of some forwarding.
`Set<RemotePortForwarder.Forward>` `getActiveForwards()`
`void` `handleOpen(SSHPacket buf)` Internal API.
`protected SSHPacket` `req(String reqName, RemotePortForwarder.Forward forward)`

Methods inherited from class net.schmizz.sshj.connection.channel.forwarded.AbstractForwardedChannelOpener
`callListener, getChannelType`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### PF_REQ

    protected static final String PF_REQ

See Also:
  Constant Field Values

### PF_CANCEL

    protected static final String PF_CANCEL

See Also:
  Constant Field Values

### listeners

    protected final Map<RemotePortForwarder.Forward,ConnectListener> listeners

Constructor Detail

### RemotePortForwarder

    public RemotePortForwarder(Connection conn)

Method Detail

### bind

    public RemotePortForwarder.Forward bind(RemotePortForwarder.Forward forward,
                                            ConnectListener listener)
                                     throws ConnectionException,
                                            TransportException

  Request forwarding from the remote host on the specified `RemotePortForwarder.Forward`. Forwarded connections will be handled by supplied `listener`.

  If `forward` specifies as 0, the returned forward will have the correct port number as informed by remote host.

  Parameters:
    `forward` - the `RemotePortForwarder.Forward` to put in place on remote host
    `listener` - the listener which will next forwarded connection
  Returns:
    the `RemotePortForwarder.Forward` which was put into place on the remote host
  Throws:
    `ConnectionException` - if there is an error requesting the forwarding
    `TransportException`

### cancel

    public void cancel(RemotePortForwarder.Forward forward)
                throws ConnectionException,
                       TransportException

  Request cancellation of some forwarding.

  Parameters:
    `forward` - the forward which is being cancelled
  Throws:
    `ConnectionException` - if there is an error with the cancellation request
    `TransportException`

### req

    protected SSHPacket req(String reqName,
                            RemotePortForwarder.Forward forward)
                     throws ConnectionException,
                            TransportException

  Throws:
    `ConnectionException`
    `TransportException`

### getActiveForwards

    public Set<RemotePortForwarder.Forward> getActiveForwards()

  Returns:
    the active forwards.

### handleOpen

    public void handleOpen(SSHPacket buf)
                    throws ConnectionException,
                           TransportException

  Internal API. Creates a `RemotePortForwarder.ForwardedTCPIPChannel` from the `CHANNEL_OPEN` request and calls associated `ConnectListener` for that forward in a separate thread.

  Parameters:
    `buf` - `SSHPacket` containg the request except for the message identifier and channel type field
  Throws:
    `ConnectionException`
    `TransportException`

Copyright © 2009-2011. All Rights Reserved.