From 84a1bd55198f2714f7f383bcd2ff2c5f09d1148c Mon Sep 17 00:00:00 2001 From: GT610 <79314033+GT-610@users.noreply.github.com> Date: Thu, 22 Jan 2026 13:49:48 +0800 Subject: [PATCH] fix(sftp): FIx Permission Denied While Accessing SFTP (#1019) * fix(storage): Set the initial SFTP path based on the user's role When the user is not root, set the initial path to `/home/$user`. For root users, use `/root` as the path * chore: Add issue participants into github_id * fix(sftp): Improved the logic for obtaining the initial path and asynchronously processed directory listings Attempt to obtain the user's home directory path by executing a command, and fall back to the default path if it fails. At the same time, change the _listDir call to asynchronous to avoid potential issues. * fix(storage): Fixed the logic for determining the initial path of SFTP Change the condition from checking if the path is not equal to '~' to checking if the path starts with '/', to ensure the correct user home directory path is obtained --- lib/data/res/github_id.dart | 6 ++++++ lib/view/page/storage/sftp.dart | 21 ++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/data/res/github_id.dart b/lib/data/res/github_id.dart index f3aae607..675654a9 100644 --- a/lib/data/res/github_id.dart +++ b/lib/data/res/github_id.dart @@ -131,6 +131,12 @@ abstract final class GithubIds { 'Lancerys', 'yaziku', 'yeluosln', + 'FadeFx', + 'Snihc1205', + 'Bjups', + '4061N', + 'itmagpro', + 'atikattar1104' }; } diff --git a/lib/view/page/storage/sftp.dart b/lib/view/page/storage/sftp.dart index 7c405cf0..b3f40bb9 100644 --- a/lib/view/page/storage/sftp.dart +++ b/lib/view/page/storage/sftp.dart @@ -79,8 +79,23 @@ class _SftpPageState extends ConsumerState with AfterLayoutMixin { } @override - FutureOr afterFirstLayout(BuildContext context) { - var initPath = '/'; + FutureOr afterFirstLayout(BuildContext context) async { + String initPath; + + try { + final homeResult = await _client.run('eval echo ~${widget.args.spi.user}'); + final homePath = homeResult.string.trim(); + if (homePath.isNotEmpty && homePath.startsWith('/')) { + initPath = homePath; + } else { + final user = widget.args.spi.user; + initPath = user != 'root' ? '/home/$user' : '/root'; + } + } catch (_) { + final user = widget.args.spi.user; + initPath = user != 'root' ? '/home/$user' : '/root'; + } + if (Stores.setting.sftpOpenLastPath.fetch()) { final history = Stores.history.sftpLastPath.fetch(widget.args.spi.id); if (history != null) { @@ -89,7 +104,7 @@ class _SftpPageState extends ConsumerState with AfterLayoutMixin { } _status.path.path = widget.args.initPath ?? initPath; - _listDir(); + unawaited(_listDir()); } }