fix: 内置 dartssh2 2.11.0 补丁版(third_party 本地依赖),修复新版 Dart SDK 下 sftp_client 编译错误
This commit is contained in:
1 parent
6daa9dd361
commit
0a33fabec2
139 files changed
+16497
-1
No files matched your search
+24
@@ -0,0 +1,24 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartssh2/dartssh2.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);
|
||||
},
|
||||
);
|
||||
|
||||
final uptime = await client.run('uptime');
|
||||
print(utf8.decode(uptime));
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
|
||||
void main(List<String> args) async {
|
||||
final client = SSHClient(
|
||||
await SSHSocket.connect('localhost', 22),
|
||||
username: 'root',
|
||||
onPasswordRequest: () {
|
||||
stdout.write('Password: ');
|
||||
stdin.echoMode = false;
|
||||
return stdin.readLineSync() ?? exit(1);
|
||||
},
|
||||
);
|
||||
|
||||
final session = await client.execute('cat > file.txt');
|
||||
await File('local_file.txt').openRead().cast<Uint8List>().pipe(session.stdin);
|
||||
|
||||
await session.done;
|
||||
print('done');
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartssh2/dartssh2.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 serverSocket = await ServerSocket.bind('localhost', 8080);
|
||||
|
||||
print('Listening on ${serverSocket.address.address}:${serverSocket.port}');
|
||||
|
||||
await for (final socket in serverSocket) {
|
||||
final forward = await client.forwardLocal('httpbin.org', 80);
|
||||
forward.stream.cast<List<int>>().pipe(socket);
|
||||
socket.cast<List<int>>().pipe(forward.sink);
|
||||
}
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartssh2/dartssh2.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;
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
|
||||
void main(List<String> args) async {
|
||||
final socket = await SSHSocket.connect('localhost', 22);
|
||||
|
||||
final client = SSHClient(
|
||||
socket,
|
||||
username: 'root',
|
||||
identities: [
|
||||
// A single private key file may contain multiple keys.
|
||||
...SSHKeyPair.fromPem(await File('path/to/id_rsa').readAsString()),
|
||||
],
|
||||
);
|
||||
|
||||
final uptime = await client.run('uptime');
|
||||
print(utf8.decode(uptime));
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartssh2/dartssh2.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);
|
||||
},
|
||||
);
|
||||
|
||||
final sftp = await client.sftp();
|
||||
final files = await sftp.listdir('/');
|
||||
|
||||
for (var file in files) {
|
||||
print('${file.filename} (${file.attr.type?.name})');
|
||||
}
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartssh2/dartssh2.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);
|
||||
},
|
||||
);
|
||||
|
||||
final sftp = await client.sftp();
|
||||
final items = await sftp.listdir('/');
|
||||
|
||||
for (final item in items) {
|
||||
print(item.longname);
|
||||
}
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartssh2/dartssh2.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);
|
||||
},
|
||||
);
|
||||
|
||||
final sftp = await client.sftp();
|
||||
final file = await sftp.open('/etc/passwd');
|
||||
final content = await file.readBytes();
|
||||
print(latin1.decode(content));
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartssh2/dartssh2.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);
|
||||
},
|
||||
);
|
||||
|
||||
final sftp = await client.sftp();
|
||||
final stat = await sftp.stat('/usr');
|
||||
print(stat.size);
|
||||
print(stat.mode);
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
|
||||
void main(List<String> args) async {
|
||||
final client = SSHClient(
|
||||
await SSHSocket.connect('localhost', 22),
|
||||
username: 'root',
|
||||
onPasswordRequest: () {
|
||||
stdout.write('Password: ');
|
||||
stdin.echoMode = false;
|
||||
return stdin.readLineSync() ?? exit(1);
|
||||
},
|
||||
);
|
||||
|
||||
final sftp = await client.sftp();
|
||||
final file = await sftp.open(
|
||||
'file.txt',
|
||||
mode: SftpFileOpenMode.truncate | SftpFileOpenMode.write,
|
||||
);
|
||||
|
||||
await file.write(File('local_file.txt').openRead().cast()).done;
|
||||
print('done');
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dartssh2/dartssh2.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);
|
||||
},
|
||||
);
|
||||
|
||||
final sftp = await client.sftp();
|
||||
|
||||
final file = await sftp.open(
|
||||
'/root/test.txt',
|
||||
mode: SftpFileOpenMode.create | SftpFileOpenMode.write,
|
||||
);
|
||||
|
||||
await file.write(Stream.value(Utf8Encoder().convert('hello there!'))).done;
|
||||
await file.close();
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:dartssh2/dartssh2.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);
|
||||
},
|
||||
);
|
||||
|
||||
final shell = await client.shell();
|
||||
stdout.addStream(shell.stdout);
|
||||
stderr.addStream(shell.stderr);
|
||||
stdin.cast<Uint8List>().listen(shell.write);
|
||||
|
||||
await shell.done;
|
||||
|
||||
client.close();
|
||||
await client.done;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
|
||||
void main(List<String> args) async {
|
||||
final client = SSHClient(
|
||||
await SSHSocket.connect('<ip>', 22),
|
||||
username: '...',
|
||||
onPasswordRequest: () => '...',
|
||||
);
|
||||
|
||||
final httpClient = SSHHttpClient(client);
|
||||
final request = httpClient.get(Uri.parse('http://httpbin.org/get'));
|
||||
final response = await request.close();
|
||||
print(response.body);
|
||||
|
||||
client.close();
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
|
||||
void main() async {
|
||||
final jumpServer = SSHClient(
|
||||
await SSHSocket.connect('<jump server>', 22),
|
||||
username: '...',
|
||||
onPasswordRequest: () => '...',
|
||||
);
|
||||
|
||||
final client = SSHClient(
|
||||
await jumpServer.forwardLocal('<target server>', 22),
|
||||
username: '...',
|
||||
onPasswordRequest: () => '...',
|
||||
);
|
||||
|
||||
print(utf8.decode(await client.run('hostname')));
|
||||
print(utf8.decode(await client.run('ifconfig')));
|
||||
|
||||
client.close();
|
||||
jumpServer.close();
|
||||
}
|
||||
Reference in new issue
Block a user