basic file exploration and bugfixes
This commit is contained in:
parent
8d7c90bbac
commit
0740c4b82d
5 changed files with 124 additions and 4 deletions
|
@ -39,7 +39,10 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
_connection.isEncryptionEnabled = widget.initialState?.isEncryptionEnabled;
|
||||
_connection.isDefault = widget.initialState?.isDefault;
|
||||
_privateKeyFileController.text = widget.initialState?.privateKey ?? '';
|
||||
_connection.privateKey = widget.initialState?.privateKey;
|
||||
_passwordController.text = widget.initialState?.password ?? '';
|
||||
_fileSelected = true;
|
||||
_isPrivateKeyValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,7 +138,6 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
}
|
||||
}
|
||||
catch (e) {
|
||||
print('bonga');
|
||||
setState(() {
|
||||
_fileSelected = true;
|
||||
_showPrivateKey = true;
|
||||
|
@ -168,7 +170,7 @@ class _AddServerModalState extends State<AddServerModal> {
|
|||
if (_privateKeyFileController.text.isEmpty && _passwordController.text.isEmpty) {
|
||||
return 'At least provide one of these';
|
||||
}
|
||||
if (!_isPrivateKeyValid) {
|
||||
if (_privateKeyFileController.text.isNotEmpty && !_isPrivateKeyValid) {
|
||||
return 'Invalid private key file';
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:fluxcloud/add_server_modal.dart';
|
||||
import 'package:fluxcloud/connection.dart';
|
||||
import 'package:fluxcloud/sftp_explorer.dart';
|
||||
|
||||
class SftpConnectionList extends StatefulWidget {
|
||||
const SftpConnectionList({
|
||||
|
@ -75,8 +77,21 @@ class _SftpConnectionListState extends State<SftpConnectionList> {
|
|||
color: Theme.of(context).colorScheme.onSecondary,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
// TODO: connect to connection here
|
||||
onTap: () async {
|
||||
final conn = _connections[index];
|
||||
final client = SSHClient(
|
||||
await SSHSocket.connect(conn.host!, conn.port!),
|
||||
username: conn.username!,
|
||||
onPasswordRequest: () => conn.password,
|
||||
identities: [
|
||||
if (conn.privateKey != null)
|
||||
...SSHKeyPair.fromPem(conn.privateKey!)
|
||||
]
|
||||
);
|
||||
final sftpClient = await client.sftp();
|
||||
if (context.mounted) {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => SftpExplorer(sftpClient: sftpClient,)));
|
||||
}
|
||||
},
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Padding(
|
||||
|
|
62
lib/sftp_explorer.dart
Normal file
62
lib/sftp_explorer.dart
Normal file
|
@ -0,0 +1,62 @@
|
|||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SftpExplorer extends StatefulWidget {
|
||||
const SftpExplorer({super.key, required this.sftpClient, this.path = '/'});
|
||||
|
||||
final SftpClient sftpClient;
|
||||
final String path;
|
||||
|
||||
@override
|
||||
State<SftpExplorer> createState() => _SftpExplorerState();
|
||||
}
|
||||
|
||||
class _SftpExplorerState extends State<SftpExplorer> {
|
||||
|
||||
bool _isLoading = true;
|
||||
late List<SftpName> _dirContents;
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_listDir();
|
||||
}
|
||||
|
||||
void _listDir() async {
|
||||
_dirContents = await widget.sftpClient.listdir(widget.path);
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Explorer'),
|
||||
),
|
||||
body: _isLoading ? Center(child: CircularProgressIndicator()) : ListView.builder(
|
||||
itemCount: _dirContents.length,
|
||||
itemBuilder: (context, index) {
|
||||
final dirEntry = _dirContents[index];
|
||||
return ListTile(
|
||||
leading: Icon(dirEntry.attr.isDirectory ? Icons.folder : Icons.description),
|
||||
title: Text(dirEntry.filename),
|
||||
onTap: () {
|
||||
if (dirEntry.attr.isDirectory) {
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (context) => SftpExplorer(
|
||||
sftpClient: widget.sftpClient,
|
||||
path: '${widget.path}${dirEntry.filename}/',
|
||||
)
|
||||
));
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue