diff --git a/lib/view/page/storage/sftp.dart b/lib/view/page/storage/sftp.dart index 4c7279bf..18f49575 100644 --- a/lib/view/page/storage/sftp.dart +++ b/lib/view/page/storage/sftp.dart @@ -99,7 +99,16 @@ class _SftpPageState extends ConsumerState with AfterLayoutMixin { if (Stores.setting.sftpOpenLastPath.fetch()) { final history = Stores.history.sftpLastPath.fetch(widget.args.spi.id); if (history != null) { - initPath = history; + SftpClient? sftp; + try { + final normalizedHistory = _normalizeSftpPath(history); + sftp = await _client.sftp(); + await sftp.listdir(normalizedHistory); + initPath = normalizedHistory; + } catch (_) { + } finally { + sftp?.close(); + } } } @@ -639,7 +648,8 @@ extension _Actions on _SftpPageState { // Only update history when success if (Stores.setting.sftpOpenLastPath.fetch()) { - Stores.history.sftpLastPath.put(widget.args.spi.id, listPath); + final normalizedPath = _normalizeSftpPath(listPath); + Stores.history.sftpLastPath.put(widget.args.spi.id, normalizedPath); } return true; @@ -789,6 +799,8 @@ extension _Actions on _SftpPageState { } } +String _normalizeSftpPath(String path) => path.replaceAll(RegExp(r'/+'), '/'); + String? _getDecompressCmd(String filename) { for (final ext in _extCmdMap.keys) { if (filename.endsWith('.$ext')) {