View RSS Feed

andre_teprom

Android client SSH extension for MIT Application Inventor 2

Rate this Entry
The following attached file contains an SSH Client extension Name:  ssh_hkj_icon.png
Views: 1764
Size:  271 Bytes which I made for my own use, but it may also be useful for users of the MIT Application Inventor 2 (AI2) community, or even to the AppyBuilder community (code intrinsically compatible for the last one, but not tested). This is just the current stage of development, but if you want to get updated revisions, you can get the last released source code at Github.

Click image for larger version. 

Name:	Component.png 
Views:	259 
Size:	75.7 KB 
ID:	152955

It is being shared "as-is", which means that:

  • No implicit or expressed warranty provided - (leastwise worked for me),
  • No functional optimization performed, no refactoring made,
  • Not intended to be an "state-of-the-art" work, but rather a quick solution to a big problem,
  • Not tested in all devices, OS builds, etc... (tested on Android 4.2 and 8.1, both Samsung mobiles)
  • Attempted to follow good coding/style formatting practices, but not strictly committed to this.

This is an extension that sends simple SSH commands, and captures the returned "string" sentence. All commands execution have to be as quick as possible, once the AsynchUtil.runAsynchronously class is being used to instantiate the thread which embed the whole SSH execution (send/receive), and it is well known that this thread locks UI execution, turning the application unresponsive to the user.

Click image for larger version. 

Name:	Screen.png 
Views:	183 
Size:	12.1 KB 
ID:	152991

In the attached demo application, the text field displays only the last line, and for this reason, if you want to see the whole sentence got from host, you can make simple changes in the code in order to merge incoming messages subsequently.

Click image for larger version. 

Name:	TestApp.png 
Views:	192 
Size:	98.5 KB 
ID:	152992

It is worthy to mention that due to the oftentimes changes in the security policies of the protocols, it would not be improbable that the attached .aix file would not work in the future, therefore this extension should be re-compiled (with the Apache ANT builder), but now adding a more recent release of JSch at the LIB folder (current revision: jsch-0.1.54.jar).

Another point to remark is that, althought including the source code of the JSch library in the project, the correspondent compield JAR was necessary just to embed it into the application during build stage, without the need to give external dependencies to the user.

USAGE:
=====

1 ) Fill string variables "SetUser", "SetHost" and "SetPasswords" accordingly, without queotes
2 ) Fill string variable "Command" with the Bash/Shell command to be issued, without queotes (e.g: ls )
3 ) Call the function "SendData"
4 ) Get result either:
4.1 ) ...from within "NewIncomingMessage" event, argument "data" contains current text line, indded the last one.
4.1 ) ...by reading "GetReceivedMessage" variable; be aware that it is assyncronously updated (intermediary values are superseded)

Feel free to make experiments and give feedback.

LINKS AND TIPS

Development environment:
Source code dependencies:


Binary project dependencies:
  • JSCH : https://sourceforge.net/projects/jsc...ch.jar/0.1.54/ (note, it is the above source code compiled)
    • At Environment Variables, add to CLASSPATH:
      <main folder>\appinventor\components\runtime\jcraft\jsch \jgss
    • At \appinventor\components\ locate the file Build.xml and seek for the comment header CopyComponentLibraries and add the following sentence:
      <copy toFile="${public.deps.dir}/jsch-0.1.54.jar" file="${lib.dir}/jsch/jsch-0.1.54.jar" />
Required/Preferred tools:
How to create Extensions:
Attached Thumbnails Attached Files
Categories
Uncategorized

Comments