### External Jar jSch

Using jSch with help of Library JavaObject.
Additional jar to include: jsch-0.1.51
Reference: http://www.jcraft.com/jsch/
Notes:
• The version of the additional Jar might have changed. Lookup the related website.
JavaObject Example executing ls command on Remote Host
'Ensure #AdditionalJar: jsch-0.1.51
`Sub ExecuteRemoteCommand
Dim hostcmd As String = "ls"
Dim user As String = "tf"
Dim host As String = "192.168.0.10"
Dim port As Int = 22
Dim pw As String = "tf"
Dim joSch As JavaObject
'Java: JSch js = new JSch();
joSch.InitializeNewInstance("com.jcraft.jsch.JSch", Null)
'Java: Session s = js.getSession("myusername", "myremotemachine.mycompany.com", 22);
Dim joS As JavaObject
joS = joSch.RunMethod("getSession", Array(user, host, port))
'Java: s.setPassword("mypassword");
joS.RunMethod("setPassword", Array(pw))
'Java: Properties config = new Properties();
Dim joP As JavaObject
joP = joP.InitializeNewInstance("java.util.Properties", Null)
'Java: config.put("StrictHostKeyChecking", "no");
joP.RunMethod("setProperty", Array("StrictHostKeyChecking", "no"))
'Java: s.setConfig(config);
joS.RunMethod("setConfig", Array(joP))
'Java: s.connect();
joS.RunMethod("connect", Null)
Log("Connected to Host...")
Log("Invoking Command..." & hostcmd )
'Java: Channel c = s.openChannel("exec");
Dim joC As JavaObject = joS.RunMethod("openChannel", Array("exec"))
joC.RunMethod("setCommand", Array(hostcmd ))
'Java: joC.RunMethod("setCommand", Array("ls -l"))
Log("Invoking Command...Connect")
joC.RunMethod("connect", Null)
Log("InputstreamReader...Build")
Dim joISR As JavaObject
'Java: BufferedReader reader = new BufferedReader(new InputStreamReader(cE.getInputStream()));
joISR.InitializeNewInstance("java.io.InputStreamReader", Array(joC.RunMethod("getInputStream", Null)))
Log("BufferedReader...Reading")
Dim joBR As JavaObject
joBR.InitializeNewInstance("java.io.BufferedReader", Array(joISR))
'Java: joBR.RunMethod("readLine", Null)
Log("Result Command " & hostcmd )
Dim s As String
Do While s.Contains("null") = False
s = joBR.RunMethod("readLine", Null)
If s <> "null" Then Log(s)
Loop
End Sub`
Inline Java Example executing ls command on Remote Host
'Ensure #AdditionalJar: jsch-0.1.51
`Sub Process_Globals
...
Public NativeMe As JavaObject
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
NativeMe = Me
jSch_ExecuteRemoteCommandEx
End Sub`
'Example executing ls command on remote host using jSch
'Ensure #AdditionalJar: jsch-0.1.51
`Sub jSch_ExecuteRemoteCommandEx
Log("ExecuteRemoteCommandEx :: Start")
Dim l As List = NativeMe.RunMethod("jschexeccmd", Array("username", "hostaddress", "password", "hostcommand"))
Log("Result (Lines:" & l.Size & ")")
For i = 0 To l.Size - 1
Log(l.Get(i))
Next
Log("ExecuteRemoteCommandEx :: End")
End Sub`
#If JAVA
import java.util.*;
import java.io.*;
import com.jcraft.jsch.*;
public static List

Changed: , Category: Jar, File: T6C204M1498.htm, ID: 1498