forked from TerminalStudio/dartssh2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforward_remote.dart
37 lines (28 loc) · 871 Bytes
/
forward_remote.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import 'dart:io';
import 'package:dartssh3/dartssh3.dart';
void main(List<String> args) async {
final socket = await SSHSocket.connect('localhost', 22);
final client = SSHClient(
socket,
username: 'root',
onPasswordRequest: () {
stdout.write('Password: ');
stdin.echoMode = false;
return stdin.readLineSync() ?? exit(1);
},
);
await client.authenticated;
final forward = await client.forwardRemote(port: 2222);
if (forward == null) {
print('Failed to forward remote port');
exit(1);
}
print('Forwarding remote port 2222 to localhost:22');
await for (final connection in forward.connections) {
final socket = await Socket.connect('localhost', 22);
connection.stream.cast<List<int>>().pipe(socket);
socket.cast<List<int>>().pipe(connection.sink);
}
client.close();
await client.done;
}