fix: use SFTP readdir for file listing to support MikroTik and non-Linux systems #495

Merged
ZacharyZcR merged 1 commits from fix/mikrotik-file-manager into dev-1.10.1 2026-01-12 07:28:18 +00:00
ZacharyZcR commented 2026-01-12 06:26:34 +00:00 (Migrated from github.com)

Summary

  • Uses SFTP readdir as primary method for listing files
  • Falls back to ls -la when SFTP is unavailable
  • Enables file manager to work on MikroTik RouterOS and other non-Linux systems

Root Cause

MikroTik devices run RouterOS, which doesn't have standard Linux commands like ls. The file manager was using ls -la exclusively, causing failures on non-Linux systems.

Changes

  • Added modeToPermissions() helper to convert POSIX mode to permission string
  • Added formatMtime() helper to format Unix timestamps like ls -la output
  • Refactored /ssh/file_manager/ssh/listFiles to use trySFTP + tryFallbackMethod pattern
  • SFTP readlink() is used to resolve symlink targets

Data Format Notes

Field SFTP ls -la fallback
owner/group uid/gid numbers username/groupname
permissions converted from mode direct string
linkTarget via readlink() parsed from " -> "

Test plan

  • Test on MikroTik device - should now display file list
  • Test on Linux server - should work with SFTP (preferred) or fallback
  • Test with symlinks - linkTarget should be resolved
  • Test permission display (755, 644, etc.)

Fixes Termix-SSH/Support#317

## Summary - Uses SFTP `readdir` as primary method for listing files - Falls back to `ls -la` when SFTP is unavailable - Enables file manager to work on MikroTik RouterOS and other non-Linux systems ## Root Cause MikroTik devices run RouterOS, which doesn't have standard Linux commands like `ls`. The file manager was using `ls -la` exclusively, causing failures on non-Linux systems. ## Changes - Added `modeToPermissions()` helper to convert POSIX mode to permission string - Added `formatMtime()` helper to format Unix timestamps like ls -la output - Refactored `/ssh/file_manager/ssh/listFiles` to use trySFTP + tryFallbackMethod pattern - SFTP `readlink()` is used to resolve symlink targets ## Data Format Notes | Field | SFTP | ls -la fallback | |-------|------|-----------------| | owner/group | uid/gid numbers | username/groupname | | permissions | converted from mode | direct string | | linkTarget | via readlink() | parsed from " -> " | ## Test plan - [ ] Test on MikroTik device - should now display file list - [ ] Test on Linux server - should work with SFTP (preferred) or fallback - [ ] Test with symlinks - linkTarget should be resolved - [ ] Test permission display (755, 644, etc.) Fixes Termix-SSH/Support#317
Sign in to join this conversation.