Continue to Site

# Android client SSH extension for MIT Application Inventor 2

The following attached file contains an SSH Client extension
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.

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.

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.

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.

Development environment:
Source code dependencies:

Binary project dependencies:
• JSCH : https://sourceforge.net/projects/jsch/files/jsch.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:

There are no comments to display.

Author
andre_luis
Views
4,079
Last update