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

Add remote port forward #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:4.1.0'
}
}

Expand Down
24 changes: 24 additions & 0 deletions android/src/main/java/sq/flutter/ssh/SshPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public void onMethodCall(MethodCall call, Result rawResult) {
execute((HashMap) call.arguments, result);
} else if (call.method.equals("portForwardL")) {
portForwardL((HashMap) call.arguments, result);
} else if (call.method.equals("portForwardR")) {
portForwardR((HashMap) call.arguments, result);
} else if (call.method.equals("startShell")) {
startShell((HashMap) call.arguments, result);
} else if (call.method.equals("writeToShell")) {
Expand Down Expand Up @@ -318,6 +320,28 @@ public void run() {
}).start();
}

private void portForwardR(final HashMap args, final Result result) {
new Thread(new Runnable() {
public void run() {
try {
SSHClient client = getClient(args.get("id").toString(), result);
if (client == null)
return;

Session session = client._session;
int rport = Integer.parseInt(args.get("rport").toString());
int lport = Integer.parseInt(args.get("lport").toString());
String rhost = args.get("rhost").toString();
session.setPortForwardingR(rport, rhost, lport);
result.success(args.get("lport").toString());
} catch (JSchException error) {
Log.e(LOGTAG, "Error connecting portforwardR:" + error.getMessage());
result.error("portforwardR_failure", error.getMessage(), null);
}
}
}).start();
}

private void startShell(final HashMap args, final Result result) {
new Thread(new Runnable() {
public void run() {
Expand Down
10 changes: 10 additions & 0 deletions lib/ssh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ class SSHClient {
return result;
}

Future<String> portForwardR(int rport, int lport, String rhost) async {
var result = await _channel.invokeMethod('portForwardR', {
"id": id,
"rhost": rhost,
"rport": rport,
"lport": lport
});
return result;
}

Future<String> startShell({
String ptyType = "vanilla", // vanilla, vt100, vt102, vt220, ansi, xterm
Callback callback,
Expand Down