1313import com .jcraft .jsch .ChannelSftp ;
1414import com .jcraft .jsch .ChannelSftp .LsEntry ;
1515import com .jcraft .jsch .ChannelShell ;
16+ import com .jcraft .jsch .HostKey ;
1617import com .jcraft .jsch .JSch ;
1718import com .jcraft .jsch .JSchException ;
1819import com .jcraft .jsch .Session ;
@@ -195,8 +196,14 @@ public void onMethodCall(MethodCall call, @NonNull Result rawResult) {
195196 case "disconnect" :
196197 disconnect ((HashMap ) call .arguments );
197198 break ;
198- case "isConnected" :
199- isConnected ((HashMap ) call .arguments , result );
199+ case "flutterIsConnected" :
200+ flutterIsConnected ((HashMap ) call .arguments , result );
201+ break ;
202+ case "getHostFingerprint" :
203+ getHostFingerprint ((HashMap ) call .arguments , result );
204+ break ;
205+ case "getRemoteBanner" :
206+ getRemoteBanner ((HashMap ) call .arguments , result );
200207 break ;
201208 default :
202209 result .notImplemented ();
@@ -207,6 +214,7 @@ public void onMethodCall(MethodCall call, @NonNull Result rawResult) {
207214 private static class SSHClient {
208215 Session _session ;
209216 String _key ;
217+ String _hostKey ;
210218 BufferedReader _bufferedReader ;
211219 DataOutputStream _dataOutputStream ;
212220 Channel _channel = null ;
@@ -275,6 +283,11 @@ private void connectToHost(final HashMap args, final Result result) {
275283 SSHClient client = new flutter .ssh2 .SshPlugin .SSHClient ();
276284 client ._session = session ;
277285 client ._key = key ;
286+
287+ HostKey hostKey = session .getHostKey ();
288+ client ._hostKey = hostKey .getHost ()+" " +
289+ hostKey .getType ()+" " +
290+ hostKey .getFingerPrint (jsch );
278291 clientPool .put (key , client );
279292
280293 Log .d (LOGTAG , "Session connected" );
@@ -443,7 +456,6 @@ private void sftpLs(final HashMap args, final Result result) {
443456 SSHClient client = clientPool .get (args .get ("id" ));
444457 ChannelSftp channelSftp = Objects .requireNonNull (client )._sftpSession ;
445458
446- @ SuppressWarnings ("unchecked" )
447459 Vector <LsEntry > files = channelSftp .ls (Objects .requireNonNull (args .get ("path" )).toString ());
448460 List <Map <String , Object >> response = new ArrayList <>();
449461
@@ -601,15 +613,29 @@ private void disconnect(final HashMap args) {
601613 client ._session .disconnect ();
602614 }
603615
604- private void isConnected (final HashMap args , final Result result ) {
616+ private void flutterIsConnected (final HashMap args , final Result result ) {
605617 SSHClient client = clientPool .get (args .get ("id" ));
606618 if (client == null ) {
607619 result .success ("false" );
608620 } else if ( client ._session == null || ! client ._session .isConnected ()) {
609621 result .success ("false" );
610622 } else {
611623 result .success ("true" );
612- }
624+ }
625+ }
626+
627+ private void getHostFingerprint (final HashMap args , final Result result ) {
628+ SSHClient client = clientPool .get (args .get ("id" ));
629+ if (client != null ) {
630+ result .success (client ._hostKey );
631+ }
632+ }
633+
634+ private void getRemoteBanner (final HashMap args , final Result result ) {
635+ SSHClient client = clientPool .get (args .get ("id" ));
636+ if (client != null ) {
637+ result .success (client ._session .getServerVersion ());
638+ }
613639 }
614640
615641 private void sendEvent (Map <String , Object > event ) {
0 commit comments