shaqian / flutter_ssh

SSH and SFTP client for Flutter
https://pub.dartlang.org/packages/ssh
MIT License
117 stars 83 forks source link

iOS await connect() blocks the app #23

Open michcio53 opened 4 years ago

michcio53 commented 4 years ago

When doing stream from await connect() it is blocking the app.

Stream<String> timedConnectionContinous() async* {
    bool shoudRepeat = true;
    while (shoudRepeat) {
      try {
        String response = await connect();
        yield response;
        if (response == "session_connected") break;
      } catch (e) {
        yield "not connected";
      }
      await Future.delayed(Duration(seconds: 10));
    }
  }

How to solve it?

JeromeSallmann commented 4 years ago

Same issue, here, for Flutter web:

var client = SSHClient(host: "my.server", port: 22, username: "myUser", passwordOrKey: "myPassword",);
debugPrint("Debut des actions avec le FTP...");
try {
  client.connect().then((String result) {
    debugPrint("ConnectResult : " + result);
    client.connectSFTP().then((String result) {
      debugPrint("ConnectFTPResult : " + result);
      client.sftpDownload(path: "./cours/$file", toPath: "./cours/$file").then((String resultDownload) {
        debugPrint("GetFileResult : " + resultDownload);
        client.disconnectSFTP().then((dynamic result){
          client.disconnect();
          OpenFile.open("./cours/$file").then((String result) {
            debugPrint("Open file result : " + result);
          });
        });
      });
    });
  });
} on PlatformException catch (e) {
  debugPrint('Error: ${e.code}\nError Message: ${e.message}');
}

The app displays the first log and hangs there...

EDIT: Working on Android.

shaqian commented 4 years ago

Hi,

Are you able to debug the app in XCode or Android Studio? (Not sure if it's possible with Flutter web.)

Please set a breakpoint in the connectToHost() function then step in to see where it gets stuck.

For iOS: https://github.com/shaqian/flutter_ssh/blob/master/ios/Classes/SshPlugin.m#L114 For Android: https://github.com/shaqian/flutter_ssh/blob/master/android/src/main/java/sq/flutter/ssh/SshPlugin.java#L215

Thanks, Qian

smalol-reesco commented 4 years ago

Does it work on Flutter web chanel? After calling client.connect() there is no exception and the function never ends. It never goes to the next line, it looks like it is all the time doing something. There is no timeout also.