-
-
Notifications
You must be signed in to change notification settings - Fork 471
Description
Describe the bug
SFTP file download functionality fails on Windows due to multiple path handling issues:
- Invalid folder name: Uses
spi.oldId(format:user@ip:port) as folder name, which contains characters illegal on Windows (@and:) - Path separator mismatch: Mixes Unix-style forward slashes (
/) with Windows backslashes (\), resulting in malformed paths likeC:\Users\...\root@127.0.0.1:22\//root\compose - RangeError: Substring operations use hardcoded
/separator whilelocalPathuses platform-specific separators, causinglastIndexOfto return -1
This only happens on Windows, as other platforms use / as seperator, which won't cause any issue.
To Reproduce
Steps to reproduce the behavior:
- Run the application on Windows
- Navigate to the SFTP file browser for a remote server
- Attempt to download a file from the remote server
- Observe the error messages in the logs
This error also exists in File page, while opening a folder.
Error Messages
[package:server_box/main.dart:73] [WARNING] App: Exception: sftp worker event: PathNotFoundException: Exists failed, path = 'C:\Users\...\AppData\Roaming\ServerBox\file\root@127.0.0.1:22\\\root\compose' (OS Error: 文件名、目录名或卷标语法不正确。, errno = 123)
[package:server_box/main.dart:73] [WARNING] App: Exception: sftp worker event: RangeError (end): Invalid value: Not in inclusive range 0..95: -1
Desired Results
- Files should download successfully on Windows
- Folder names should use valid characters for all platforms (e.g., use
spi.idinstead ofspi.oldId) - Path separators should be consistent and platform-appropriate
- No RangeError exceptions during file operations
Actual Results
- File download fails with PathNotFoundException
- Invalid folder names are created on Windows
- Path separators are mixed, creating malformed paths
- RangeError occurs due to incorrect separator usage in substring operations
Root Cause Analysis
The issues stem from inconsistent path handling across the codebase:
- sftp.dart:589: Uses
spi.oldIdinstead ofspi.idfor folder naming - sftp.dart:589: Does not strip leading separator from
normalizedPath, causing triple separators - worker.dart:73: Uses hardcoded
/instead ofPfs.seperatorinlastIndexOf - req.dart:39: Uses hardcoded
/instead ofPfs.seperatorinsplit
Proposed Fixes
Device
- OS: Windows 11
- Platform: Windows
- ServerBox version: v1276
Additional context
ServerBox generates server IDs using ShortId.generate() (e.g., ptPQHje00), which are valid folder names on all platforms. However, the code currently uses spi.oldId (format: user@ip:port) for folder naming.
I'm investigating into this issue and have applied some fixes, but I'm checking if there are more problems about this.
After that I'll create a PR.