Hello Atsuhiko (and other interested parties), I tried to open a direct-tcpip channel to some TCP server which replies with a message and immediately closes the connection. (See [0] for background.)
When trying this with the StreamForwarding example, it shows the output and then throws an JSchException (in `.connect()`). When modifying the example to use `getInputStream()` instead of `setOutputStream()`, it only throws the exception and I don't get to read from the stream because of the exception. I added quite some debugging commands to Session.run [1] to localize the problem. At the end [2] is the output when adding the logger from the Logger example. The same problem occurs if I use socket-forwarding (PortForwardingL), but the PortWatcher's run() loop silently discards the exception. I added a logging call in the catch block, see below [3] for example output (last line shows the exception, without stack trace). As we can see, the remote host sends an SSH_MSG_CHANNEL_EOF before our channel's connect() method had the chance to even see that the connection is open, and thus it throws an exception instead of simply returning. Solution idea: We should in the Session's packet read loop somehow treat SSH_MSG_CHANNEL_OPEN_FAILURE differently than SSH_MSG_CHANNEL_EOF. Now, both are calling channel.remote_eof(), and this is used by the ChannelDirectTCPIP to tell wether the connection was successful. Maybe the ChannelDirectTCPIP could use the exit code, or another additional status variable instead of remote_eof for this decision. PaĆlo [0] Background: I wanted to create a general SocketImpl based on JSch's ChannelDirectTCPIP, so I can implement a SocketFactory or similar things for other libraries (like RMI or Webservice calls). I searched a bit for a simple enough server to test this, and finally used a server I'm working with on my current project (the same one that got me to JSch, and where I'm using the ProxySSH I posted some weeks ago). Normally this is used with "telnet localhost 2006". I think another example with similar behaviour would be the standard Daytime service as defined in RFC 861. When my TunnelSocketImpl not worked (same exception as described), I tried with the official examples. [1] I commited the latest changes to the better-examples branch of my github repository. You can view the source here: <https://github.com/ePaul/jsch-documentation/blob/better-examples/src/com/jcraft/jsch/Session.java#L1300> (I think I will move this to the master branch later.) [2] Log output from StreamForwarding example with added logger. The lines starting with 10.5. are on stdout, what the remote host sent. The rest is logging output on stderr. INFO: Connecting to 141.20.23.223 port 22 INFO: Connection established INFO: Remote version string: SSH-2.0-dropbear_0.52 INFO: Local version string: SSH-2.0-JSCH-0.1.44 INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256 INFO: SSH_MSG_KEXINIT sent INFO: SSH_MSG_KEXINIT received INFO: kex: server->client aes128-ctr hmac-md5 none INFO: kex: client->server aes128-ctr hmac-md5 none INFO: SSH_MSG_KEXDH_INIT sent INFO: expecting SSH_MSG_KEXDH_REPLY INFO: ssh_rsa_verify: signature true WARN: Permanently added '141.20.23.223' (RSA) to the list of known hosts. INFO: SSH_MSG_NEWKEYS sent INFO: SSH_MSG_NEWKEYS received INFO: SSH_MSG_SERVICE_REQUEST sent INFO: SSH_MSG_SERVICE_ACCEPT received INFO: Authentications that can continue: publickey,keyboard-interactive,password INFO: Next authentication method: publickey INFO: Authentications that can continue: password INFO: Next authentication method: password INFO: Authentication succeeded (password). System.{in,out} will be forwarded to localhost:2006. DEBUG: waiting for channel reply ... DEBUG: packet received, type: 91 INFO: SSH_MSG_CHANNEL_OPEN_CONFIRMATION received, channel: 0 DEBUG: packet received, type: 94 INFO: SSH_MSG_CHANNEL_DATA received, channel: 0, len: 772 10.7.205.149,1353052,5242911,37,2,0 10.5.59.109,1353031,5242920,1000,1,0 10.5.58.253,1353072,5242964,36,2,0 10.7.205.151,1353009,5243308,51,2,0 10.5.59.93,1353008,5242896,86,2,0 10.7.205.153,1353333,5243057,60,2,0 10.5.59.150,1353085,5242948,74,2,0 10.5.70.9,1352998,5243159,55,2,0 10.5.59.159,1353108,5242965,55,2,0 10.5.70.16,1353094,5242978,52,2,0 10.5.70.8,1353145,5243099,51,2,0 10.5.59.151,1353205,5242922,86,2,0 10.5.59.142,1352973,5242900,58,2,0 10.5.59.147,1353018,5242996,41,2,0 10.5.70.54,1353130,5242946,33,2,0 10.5.59.161,1353426,5243212,59,2,0 10.5.70.12,1353128,5242955,71,2,0 10.5.59.117,1353091,5242902,103,2,0 10.5.59.111,1353086,5242954,14,2,0 10.5.59.153,1353032,5242921,56,2,0 10.7.205.14,1353035,5242951,1000,1,0 10.5.58.251,1353129,5242940,1000,1,0 DEBUG: packet received, type: 96 INFO: SSH_MSG_CHANNEL_EOF received, channel: 0 DEBUG: packet received, type: 97 INFO: SSH_MSG_CHANNEL_CLOSE received, channel: 0 DEBUG: ... finished waiting for channel reply Exception in thread "main" com.jcraft.jsch.JSchException: channel is not opened: remote EOF at com.jcraft.jsch.ChannelDirectTCPIP.connect(ChannelDirectTCPIP.java:127) at StreamForwarding.main(StreamForwarding.java:60) ----------- [3] Logging output from PortForwardingL example with added logger. INFO: Connecting to 141.20.23.223 port 22 INFO: Connection established INFO: Remote version string: SSH-2.0-dropbear_0.52 INFO: Local version string: SSH-2.0-JSCH-0.1.44 INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256 INFO: SSH_MSG_KEXINIT sent INFO: SSH_MSG_KEXINIT received INFO: kex: server->client aes128-ctr hmac-md5 none INFO: kex: client->server aes128-ctr hmac-md5 none INFO: SSH_MSG_KEXDH_INIT sent INFO: expecting SSH_MSG_KEXDH_REPLY INFO: ssh_rsa_verify: signature true WARN: Permanently added '141.20.23.223' (RSA) to the list of known hosts. INFO: SSH_MSG_NEWKEYS sent INFO: SSH_MSG_NEWKEYS received INFO: SSH_MSG_SERVICE_REQUEST sent INFO: SSH_MSG_SERVICE_ACCEPT received INFO: Authentications that can continue: publickey,keyboard-interactive,password INFO: Next authentication method: publickey INFO: Authentications that can continue: password INFO: Next authentication method: password INFO: Authentication succeeded (password). localhost:2007 -> localhost:2006 DEBUG: waiting for channel reply ... DEBUG: packet received, type: 91 INFO: SSH_MSG_CHANNEL_OPEN_CONFIRMATION received, channel: 0 DEBUG: packet received, type: 94 INFO: SSH_MSG_CHANNEL_DATA received, channel: 0, len: 774 DEBUG: packet received, type: 96 INFO: SSH_MSG_CHANNEL_EOF received, channel: 0 DEBUG: packet received, type: 97 INFO: SSH_MSG_CHANNEL_CLOSE received, channel: 0 DEBUG: ... finished waiting for channel reply WARN: com.jcraft.jsch.JSchException: channel is not opened: remote EOF ------------------------------------------------------------------------------ What Every C/C++ and Fortran developer Should Know! Read this article and learn how Intel has extended the reach of its next-generation tools to help Windows* and Linux* C/C++ and Fortran developers boost performance applications - including clusters. http://p.sf.net/sfu/intel-dev2devmay _______________________________________________ JSch-users mailing list JSch-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jsch-users