Connecting to remote Windows machine with JSch
<p>I want to execute command on remote system and want to get result of the same.</p>
<p>I tried following code:</p>
<pre><code>package rough;
import java.io.InputStream;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

public class RemoteSSH {

    public static void main(String[] args) {
        String host = &quot;\\\\10.209.110.114&quot;;
        String user = &quot;Administrator&quot;;
        String password = &quot;Admin123&quot;;
        String command1 = &quot;ipconfig&quot;;
        try {
            java.util.Properties config = new java.util.Properties();
            config.put(&quot;StrictHostKeyChecking&quot;, &quot;no&quot;);
            JSch jsch = new JSch();
            Session session = jsch.getSession(user, host, 22);
            session.setPassword(password);
            session.setConfig(config);
            session.connect();
            System.out.println(&quot;Connected&quot;);

            Channel channel = session.openChannel(&quot;exec&quot;);
            ((ChannelExec) channel).setCommand(command1);
            channel.setInputStream(null);
            ((ChannelExec) channel).setErrStream(System.err);

            InputStream in = channel.getInputStream();
            channel.connect();
            byte[] tmp = new byte[1024];
            while (true) {
                while (in.available() &gt; 0) {
                    int i = in.read(tmp, 0, 1024);
                    if (i &lt; 0)
                        break;
                    System.out.print(new String(tmp, 0, i));
                }
                if (channel.isClosed()) {
                        System.out.println(&quot;exit-status: &quot; + channel.getExitStatus());
                    break;
                }
                try {
                    Thread.sleep(1000);
                } catch (Exception ee) {
                }
            }
            channel.disconnect();
            session.disconnect();
            System.out.println(&quot;DONE&quot;);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 }
</code></pre>
<p>But I am getting following error:</p>
<pre class="lang-none prettyprint-override"><code>com.jcraft.jsch.JSchException: java.lang.IllegalArgumentException: protocol = socket host = null
    at com.jcraft.jsch.Util.createSocket(Util.java:258)
    at com.jcraft.jsch.Session.connect(Session.java:186)
    at com.jcraft.jsch.Session.connect(Session.java:145)
    at rough.RemoteSSH.main(RemoteSSH.java:23)
Caused by: java.lang.IllegalArgumentException: protocol = socket host = null
    at sun.net.spi.DefaultProxySelector.select(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.&lt;init&gt;(Unknown Source)
    at java.net.Socket.&lt;init&gt;(Unknown Source)
    at com.jcraft.jsch.Util.createSocket(Util.java:252)
    ... 3 more
</code></pre>
<p>Any solution for it?
I have already tried with pstool also but not getting correct output.</p>
<p>After removing the <code>\\\\</code> from the hostname, I'm getting:</p>
<pre><code>com.jcraft.jsch.JSchException: java.net.ConnectException: Connection refused: connect
    at com.jcraft.jsch.Util.createSocket(Util.java:258)
    at com.jcraft.jsch.Session.connect(Session.java:186)
    at com.jcraft.jsch.Session.connect(Session.java:145)
    at rough.RemoteSSH.main(RemoteSSH.java:23)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
</code></pre>