Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

have plans to make this lib work on Flutter Windows #3

Open
insinfo opened this issue Aug 27, 2021 · 5 comments
Open

have plans to make this lib work on Flutter Windows #3

insinfo opened this issue Aug 27, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@insinfo
Copy link

insinfo commented Aug 27, 2021

I'm currently developing an App Flutter for windows, where I need to send commands to a linux server via SSH, this commands will make the server mount a network share and copy backup files to this share, I'm trying to do this with this SSH lib https://github.com/TerminalStudio/dartssh

I currently have this code:

class SshService {
  final Uri uri;
  final String user;
  final String pass;
  SSHClient client;
  bool isConnected = false;
  StreamController<String> outStream;

  SshService({
    this.uri,//ssh://192.168.133.13:22
    this.user,
    this.pass,
  });

  Future<dynamic> connnect() {
    var completer = Completer<bool>();
    outStream = StreamController<String>.broadcast();
    try {
      client = SSHClient(
        hostport: uri,//ssh://192.168.133.13:22
        login: user,
        print: print,
        termWidth: 80,
        termHeight: 25,
        termvar: 'xterm-256color',
        getPassword: () => utf8.encode(pass),
        response: (transport, data) async {
          //print('SshService@response: ${utf8.decode(data)}');
          outStream.add(utf8.decode(data));
        },
        success: () {
          isConnected = true;
          Future.delayed(Duration(seconds: 1)).then((value) => completer.complete());
          print('SshService@success');
        },
        disconnected: () {
          print('SshService@disconnected');
          isConnected = false;
        },
      );
    } catch (e, s) {
      print('SshService@connnect $e $s');
      //completer.complete();
      completer.completeError(e, s);
    }
    return completer.future;
  }

  Future<String> sendCommand(String cmd) async {
    var completer = Completer<String>();
    try {
      client.sendChannelData(utf8.encode(cmd));
      var isEnd = false;
      var result = '';
      outStream.stream.listen((data) {
        //isaque.neves@laravel:/var/www/dart$
        result += data;
        if (data.trim().endsWith('\$')) {
          //print('stream.listen $data');
          if (isEnd == false) {
            isEnd = true;
            completer.complete(result);
          }
        }
      });
    } catch (e, s) {
      print('SshService@sendCommand $e $s');
      completer.completeError(e, s);
    }
    return completer.future;
  }

  void close() {
    client?.disconnect('terminate');
    outStream?.close();
  }
}

but it doesn't seem quite right

@jda258
Copy link
Owner

jda258 commented Aug 28, 2021

This package currently doesn't support desktop operating systems. I haven't used Windows much for quite a while now, but can you use the Linux subsystem to call ssh directly using Process.run?

@jda258 jda258 added the enhancement New feature or request label Aug 28, 2021
@sandoval-san
Copy link

Opa amigo, estou com uma situação parecida, estou cria um app desktop com flutter onde preciso uma SSH FLUTTER, só que no desktop estar dando erro. o pacote é este ( https://pub.dev/packages/ssh2 ), o erro é este ( MissingPluginException(No implementation found for method listen on channel shell_sftp)). preciso resolver este problema e não sei como peço uma dica.
Obrigado

@insinfo
Copy link
Author

insinfo commented Oct 29, 2021

@sandoval-san eu fiz um um pacote que implementa os protocolos SSH/SCP/SFTP para usar com o Flutter desktop em cima da libssh, irei publicar no pub.dev

@jda258
Copy link
Owner

jda258 commented Dec 9, 2021

@insinfo I'd be very interested to see your Flutter package when it's ready. Using libssh directly through FFI is a much better solution that I've looked at some, but haven't had the time to get to yet. Let us know if we can help with development and testing efforts.

@insinfo
Copy link
Author

insinfo commented Dec 9, 2021

@jda258 @sandoval-san

I just published libssh_binding I haven't had a lot of time to document and write tests, but it's working fine for me in production, I use it for a server backup application called "fsbackup" which I'm also writing will be open source, in my internal testing i'm getting the same performance if not better than native scp, i'll be glad to get any help with documentation or improvements.

https://pub.dev/packages/libssh_binding
https://github.com/insinfo/fsbackup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants