feat: Implement accessible SFTP file browser and native editor
This commit is contained in:
@@ -110,6 +110,39 @@ class SshService {
|
||||
}
|
||||
}
|
||||
|
||||
// --- SFTP Operations ---
|
||||
|
||||
Future<SftpClient> _getSftpClient() async {
|
||||
if (_client == null) throw Exception('Not connected');
|
||||
return await _client!.sftp();
|
||||
}
|
||||
|
||||
Future<List<SftpName>> listDirectory(String path) async {
|
||||
final sftp = await _getSftpClient();
|
||||
return await sftp.listdir(path);
|
||||
}
|
||||
|
||||
Future<String> readFile(String path) async {
|
||||
final sftp = await _getSftpClient();
|
||||
|
||||
// Check file size first
|
||||
final stat = await sftp.stat(path);
|
||||
if ((stat.size ?? 0) > 1024 * 1024) { // 1MB limit
|
||||
throw Exception('File is too large to edit (Max 1MB).');
|
||||
}
|
||||
|
||||
final file = await sftp.open(path);
|
||||
final content = await file.readBytes();
|
||||
return utf8.decode(content);
|
||||
}
|
||||
|
||||
Future<void> writeFile(String path, String content) async {
|
||||
final sftp = await _getSftpClient();
|
||||
final file = await sftp.open(path, mode: SftpFileOpenMode.create | SftpFileOpenMode.write | SftpFileOpenMode.truncate);
|
||||
await file.writeBytes(utf8.encode(content));
|
||||
await file.close();
|
||||
}
|
||||
|
||||
void write(String data) {
|
||||
if (_session != null) {
|
||||
_session!.write(utf8.encode(data));
|
||||
|
||||
Reference in New Issue
Block a user