On Thu, Sep 27, 2012 at 8:44 PM, Kevin Winchester < [email protected]> wrote:
> Hi, > > I see that TCP/IP forwarding has been added to the SSHD client in the > upcoming 0.8.0 release. I have grabbed the latest code from SVN to try it > out, but I have a few questions: > > 1. Is there any sample code for how to use it? I basically am doing the > following: > > SshClient sshClient = SshClient.setUpDefaultClient()**; > sshClient.start(); > ClientSession clientSession = sshClient.connect( host, port > ).await().getSession(); > clientSession.authPassword( username, password ).await(); > clientSession.**startLocalPortForwarding( new SshdSocketAddress( > localAddress, localPort ), new SshdSocketAddress( remoteAddress, remotePort > ) ); > > I don't want any shell or execution channel, just the port forwarding. Is > that the best way to make use of the feature? > Yes > > 2. When I run the above code, the channel seems to work correctly, until I > disconnect for the first time, at which point the channel seems to close > itself. Is that something I am doing wrong, or is it the intended > behavior? Any other SSH client I have used maintains the forwarded channel > across multiple disconnects/reconnects. > I've just added a loop to the unit test we have and the current code seems to support multiple socket opening/close correctly. See testLocalForwardingNative in https://github.com/apache/mina-sshd/blob/trunk/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java#L189 Channels are created for each incoming socket connection on the remote side. Are you saying that the channel is kept opened for a certain amount of time before being closed if not reused ? I suppose I can see the use case for example when using HTTP 1.0, but I must admit that did not crossed my mind. Feel free to raise a JIRA issue and eventually propose a patch if you're fancy working on it. > 3. I see that there is a createDirectTcpipChannel method in the > ClientSession class as well, that seems to create a completely different > implementation of a forwarded TCP/IP channel. What is that used for? > The main difference is that the startLocalPortForwarding opens a server socket and will channel incoming connection through the ssh layer. The createDirectTcpipChannel serves a slightly different purpose which is to stream data from java to the remote host, so no socket is opened and you have to give the input / output / error streams instead. The reason the implementation is different is mainly because in the startLocalPortForwarding case, no java streams are used, and we use bio buffers, so even if ssh layer is used in the same way, the client side is slightly different. > > Thanks, > Kevin Winchester > -- ------------------------ Guillaume Nodet ------------------------ Blog: http://gnodet.blogspot.com/ ------------------------ FuseSource, Integration everywhere http://fusesource.com
