Binding and high-level wrapper on top of libssh - The SSH library!

Overview

Dart Binding to libssh version 0.9.6

binding and high-level wrapper on top of libssh - The SSH library! libssh is a multiplatform C library implementing the SSHv2 protocol on client and server side. With libssh, you can remotely execute programs, transfer files, use a secure and transparent tunnel https://www.libssh.org

linux (Debin/Ubuntu)
# install dart 2.14
sudo apt-get update
sudo apt-get install apt-transport-https
sudo sh -c 'wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
sudo sh -c 'wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
sudo apt-get update
sudo apt-get install dart=2.14*

# install libssh
sudo apt show libssh-4
sudo apt install libssh-4
# check
ldconfig -p | grep libssh
/lib/x86_64-linux-gnu/libssh.so.4
libssh.so.4
example of high level on Ubuntu 20
void main() async {
  var libraryPath = path.join('/lib/x86_64-linux-gnu/', 'libssh.so.4');
  print('libraryPath $libraryPath');
  final dll = DynamicLibrary.open(libraryPath);

  final libssh = LibsshWrapper('192.168.3.4',
      inDll: dll,
      username: 'isaque',
      password: 'pass',
      port: 22,
      verbosity: true);
  libssh.connect();
  final start = DateTime.now();

 
  await libssh.scpDownloadDirectory('/var/www/html/portalPmro',
      path.join(Directory.current.path, 'download'));
  
  print('\r\n${DateTime.now().difference(start)}');
  libssh.dispose();
  exit(0);
}
example of low level on Windows
import 'dart:io';
import 'package:libssh_binding/libssh_binding.dart';
import 'package:libssh_binding/src/extensions/sftp_extension.dart';
import 'dart:ffi' as ffi;
import 'package:path/path.dart' as path;

void main() async {
  // Open the dynamic library
  var libraryPath = path.join(Directory.current.path, 'libssh_compiled', 'ssh.dll');
  final dll = ffi.DynamicLibrary.open(libraryPath);
  var libssh = Libssh(dll);

  var host = "localhost";
  var port = 22;
  var password = "pass";
  var username = "root";

  // Abra a sessão e define as opções
  var my_ssh_session = libssh.ssh_new();
  libssh.ssh_options_set(my_ssh_session, ssh_options_e.SSH_OPTIONS_HOST, stringToNativeVoid(host));
  libssh.ssh_options_set(my_ssh_session, ssh_options_e.SSH_OPTIONS_PORT, intToNativeVoid(port));
  //libssh.ssh_options_set(my_ssh_session, ssh_options_e.SSH_OPTIONS_LOG_VERBOSITY, intToNativeVoid(SSH_LOG_PROTOCOL));
  libssh.ssh_options_set(my_ssh_session, ssh_options_e.SSH_OPTIONS_USER, stringToNativeVoid(username));
  // Conecte-se ao servidor
  var rc = libssh.ssh_connect(my_ssh_session);
  if (rc != SSH_OK) {
    print('Error connecting to host: $host\n');
  }

  rc = libssh.ssh_userauth_password(my_ssh_session, stringToNativeInt8(username), stringToNativeInt8(password));
  if (rc != ssh_auth_e.SSH_AUTH_SUCCESS) {
    var error = libssh.ssh_get_error(my_ssh_session.cast());
    print("Error authenticating with password:$error\n");
    //ssh_disconnect(my_ssh_session);
    //ssh_free(my_ssh_session);
  }
  String resp = '';
  // resp = libssh.execCommand(my_ssh_session, 'ls -l');
  //print("$resp");
  /*resp = libssh.execCommand(my_ssh_session, 'cd /var/www/dart && ls -l');
  print("$resp");*/

  /*resp = libssh.scpReadFileAsString(my_ssh_session, '/home/isaque.neves/teste.txt');
  print('$resp');*/

  /*await libssh.scpDownloadFileTo(
      my_ssh_session, '/home/isaque.neves/teste.txt', path.join(Directory.current.path, 'teste.txt'));*/


  /*await libssh.sftpCopyLocalFileToRemote(
      my_ssh_session, path.join(Directory.current.path, 'teste.mp4'), '/home/isaque.neves/teste.mp4');*/


  await libssh.sftpDownloadFileTo(my_ssh_session, '/home/isaque.neves/teste.mp4', path.join(Directory.current.path, 'teste.mp4'));

  libssh.ssh_disconnect(my_ssh_session);
  libssh.ssh_free(my_ssh_session);

  exit(0);
}
example of high level on Windows
import 'package:libssh_binding/libssh_binding.dart';

void main() {
  final libssh = LibsshWrapper('localhost', username: 'root', password: 'pass', port: 22);
  libssh.connect();
  final start = DateTime.now();


  //download file via SCP
  /*await libssh.scpDownloadFileTo('/home/isaque.neves/go1.11.4.linux-amd64.tar.gz',
      path.join(Directory.current.path, 'go1.11.4.linux-amd64.tar.gz'), callbackStats: (total, loaded) {
    var progress = ((loaded / total) * 100).round();
    stdout.write('\r');
    stdout.write('\r[${List.filled(((progress / 10) * 4).round(), '=').join()}] $progress%');
  });*/

  //execute command
  var re = libssh.execCommandSync('cd /var/www; ls -l');
  print(re);

  //execute command in shell
  //var re = libssh.execCommandsInShell(['cd /var/www', 'ls -l']);
  //print(re.join(''));

  //download file via SFTP
  /* await libssh.sftpDownloadFileTo(my_ssh_session, '/home/isaque.neves/go1.11.4.linux-amd64.tar.gz',
      path.join(Directory.current.path, 'go1.11.4.linux-amd64.tar.gz'));*/

 //download directory recursive
  await libssh.scpDownloadDirectory('/var/www',
      path.join(Directory.current.path, 'download'));

  print('${DateTime.now().difference(start)}');
  libssh.dispose();
}

if you want to compile libssh for android see this link Compiling libssh for Android if you need it for ios see this link libssh2 for ios, it's not for libssh, it's for libssh2 but possibly the hints should be for libssh too

You might also like...

SoundVolumeView that displays general information and the current volume level for all active sound components in your system, and allows you to instantly mute and unmute them

SoundVolumeView that displays general information and the current volume level for all active sound components in your system, and allows you to instantly mute and unmute them

SoundVolumeView that displays general information and the current volume level for all active sound components in your system, and allows you to instantly mute and unmute them

Mar 4, 2022

A wrapper around our Cocoa and Java client library SDKs, providing iOS and Android support for those using Flutter and Dart.

A wrapper around our Cocoa and Java client library SDKs, providing iOS and Android support for those using Flutter and Dart.

Ably Flutter Plugin A Flutter plugin wrapping the ably-cocoa (iOS) and ably-java (Android) client library SDKs for Ably, the platform that powers sync

Dec 13, 2022

PrestaShop Mobile Application - High Performance Flutter App

PrestaShop Mobile Application High performance mobile application developed with Flutter technology. Beside the performance and architecture the uniqu

Oct 25, 2022

A UI-based redesign of my high school's grade distribution app.

flutter_powerschool A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you

Oct 25, 2022

Flutter project that shows how to work with ObjectBox - High Performance NoSQL Database.

Flutter project that shows how to work with ObjectBox - High Performance NoSQL Database.

Flutter ObjectBox Example Flutter project that shows how to work with ObjectBox - High Performance NoSQL Database. This project shows - how to persist

Nov 1, 2022

App HTTP Client is a wrapper around the HTTP library Dio to make network requests and error handling simpler, more predictable, and less verbose.

App HTTP Client App HTTP Client is a wrapper around the HTTP library Dio to make network requests and error handling simpler, more predictable, and le

Nov 1, 2022

The lightweight and powerful wrapper library for Twitter Ads API written in Dart and Flutter 🐦

TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them. Features TODO: List w

Aug 26, 2022

An app that randomly draws Japanese vocabularies from N5 to N1 level to test your listening skill, providing pronunciation and answer checking.

An app that randomly draws Japanese vocabularies from N5 to N1 level to test your listening skill, providing pronunciation and answer checking.

An app that randomly draws Japanese vocabularies from N5 to N1 level to test your listening skill, providing pronunciation and answer checking.

Jul 17, 2022
Comments
  • library

    library "ssh.dll" not found

    Hello,

    I tried to use this library in Dart and Flutter but the code throws an exception when I instantiate LibsshWrapper. I'm running it on Ubuntu 21.04 and Dart & Flutter beta channel.

    On the Dart project (VS Code) I have this error:

    ArgumentError (Invalid argument(s): Failed to load dynamic library 'ssh.dll': ssh.dll: cannot open shared object file: No such file or directory)

    On Flutter (Android Studio):

    Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'ssh.dll': dlopen failed: library "ssh.dll" not found

    Full code (it breaks on the first line):

    import 'package:libssh_binding/libssh_binding.dart';
    
    void main(List<String> arguments) async {
      final libssh = LibsshWrapper('192.168.1.43',
          username: '***', password: '***', port: 22, verbosity: true);
    
      libssh.connect();
    
      await libssh.scpDownloadFileTo(
          '/media/***/data4t/tmp/test.jpg', '/media/***/ssd2/test.jpg');
    
      libssh.disconnect();
      libssh.dispose();
    }
    

    Thank you.

    opened by jmnicolas90 3
  • Can you make an example for Windows?

    Can you make an example for Windows?

    I'm running this code on Flutter Windows:

    //this is the method of a class
    void connect() async {
        var libraryPath = path.join(Directory.current.path, 'libssh_compiled', 'ssh.dll');
        final dll = ffi.DynamicLibrary.open(libraryPath);
    
        final libssh = LibsshWrapper(
          address,
          inDll: dll,
          username: user,
          password: 'pass',
          port: port,
          verbosity: false,
        );
        libssh.connect();
        var result = libssh.execCommandSync("ls");
        print(result);
        libssh.dispose();
        print('closed');
    }
    

    Allways returns: Unhandled Exception: Invalid argument(s): Failed to load dynamic library '<project_path>\ssh_drawer\libssh_compiled\ssh.dll': error code 126

    opened by biel-correa 0
  • Build libssh for iOS

    Build libssh for iOS

    Hi everyone,

    I've been working on building libssh for iOS based on a fork I made of https://github.com/Frugghi/iSSH2: https://github.com/jda258/iSSH2/tree/libssh_support

    I'm glad to say I was able to get a build working with this package! I wasn't able to build for the x86_64 simulator yet due to complications with the M1 CPU of my system. I'll try to get that working as well and then create a pull request for the upstream repo.

    Best, Josh

    opened by jda258 3
Owner
Isaque Neves
Isaque Neves
A wrapper on top of MFMailComposeViewController from iOS and Mail Intent on android

flutter_mailer Share email content via device Email Client - supports multiple Attachments Simple & quick plugin for cross application data sharing of

Tal Jacobson 43 May 22, 2022
A wrapper on top of alert dialog provided by flutter.

material_dialog A wrapper on top of alert dialog provided by flutter. Demo Use this package as a library 1. Depend on it Add this to your package's pu

Zubair Rehman 28 Aug 8, 2022
This plugin create a binding between your translations from .arb files and your Flutter app.

PROJECT MAINTENANCE PAUSED This project is no longer maintained due to the lack of time and availability. I'm a developer to and I know how frustratin

Razvan Lung 255 Dec 3, 2022
Aris wasmjsextend - Binding generator for FFI bindings

Binding generator for FFI bindings. Note: ffigen only supports parsing C headers

Behruz Hurramov 1 Jan 9, 2022
SSH and SFTP client for Flutter

ssh SSH and SFTP client for Flutter. Wraps iOS library NMSSH and Android library JSch. Installation Add ssh as a dependency in your pubspec.yaml file.

sha 105 Nov 29, 2022
MPV Remote: Remote control for MPV over SSH

MPV Remote Remote control for MPV over SSH. Big work-in-progress. Screenshots

Sam Lakerveld 1 Jun 2, 2022
🦀🦀 High performance Crypto library of Rust implementation for Flutter

r_crypto Rust backend support crypto flutter library, much faster than Dart-implementation library, light-weight library. Some crypto support hardware

Tino 28 Dec 17, 2022
Nimbostratus is a reactive data-fetching and client-side cache management library built on top of Cloud Firestore.

Nimbostratus ?? Nimbostratus is a reactive data-fetching and client-side cache management library built on top of Cloud Firestore. The Cloud Firestore

Dan Reynolds 13 Dec 15, 2022
Low-level link (text, URLs, emails) parsing library in Dart

linkify Low-level link (text, URLs, emails) parsing library in Dart. Required Dart >=2.12 (has null-safety support). Flutter library. Pub - API Docs -

Charles C 60 Nov 4, 2022
腾讯云 1 Feb 10, 2022