B4A Library [Libary] jkSSH2 - SSH2 communication in B4A

jkSSH2

This libary is based on Ganymed SSH-2 libary. An open source java implementation of the SSH2 protocol. The licence is included in the zip file.

Summary
This libary currently offers the following SSH2 features:
  • Several authorization methods (None/Username and Password/Key)
  • Execute shell commands on the server.
  • Create local port forwardings.
  • Download files with the scp command.
  • Upload files with the scp command.

Installation
  1. Download and unzip the attached zip file.
  2. Copy jkSSH2.jar and jkSSH2.xml to the additional libaries folder.

Example
This example shows how to execute a shell command on the server.
B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim SSH2 As jkSSH2
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
   SSH2.initialize("SSH", "hostname", 22)
   SSH2.authenticateWithPassword("username", "password")

   SSH2.execCommand("uname -a && date && uptime && who", 10)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub SSH_CmdExecuted (Success As Boolean, Result As List, TaskId As Int)
   
   Log (TaskId)
   
   If Success Then
      For i=0 To Result.Size-1
         Log(Result.Get(i) & CRLF)
      Next
   End If
   
   SSH2.close
End Sub

Sub SSH_ConnectionLost (Reason As String)
   Log(Reason)
End Sub
 

Attachments

  • jkSSH2.zip
    233.8 KB · Views: 1,038
Last edited:

DonManfred

Expert
Licensed User
Longtime User
don´t know. Search the forum.
 

Stefano Bordini

Member
Licensed User
Longtime User
Hi, i use thi library, and she work correctly in my lan, whit ssh.authenticateWithPassword connet,execute command and SSH_CmdExecuted, but now i want use in vm on google cloud and i need use ssh.authenticateWithKey,the app connect and execute command correctly,but after execute command don't trigger SSH_CmdExecuted.any suggest?
 
Top