Shell Fallback - Command Reference
When SFTP/SCP are blocked, the plugin can use shell command pipelines for file transfers. This page documents the shell commands used.
Overview
Why Shell Fallback?
- Some hosts disable SFTP subsystem
- SCP may be restricted by administrator
- Shell access often still available
- Plugin uses standard Unix commands for transfer
When to Enable
- SFTP connection fails with "Subsystem request failed"
- SCP transfers fail with permission errors
- Host policy blocks standard transfer methods
- Enable: Use shell transfer (for blocked hosts)
Transfer Methods
Method 1: Raw cat Stream
Direct streaming for simple cases:
Download
cat /remote/path/file.txt
- Outputs file content to stdout
- Plugin captures and writes to local file
- Fast, no encoding overhead
Upload
cat > /remote/path/file.txt
- Plugin sends file content to stdin
- Shell redirects to target file
- Simple but effective
Method 2: dd with Block Size
Controlled block transfer:
Download with Offset
dd if=/remote/path/file.txt bs=16384 skip=10
if= Input file path
bs= Block size (16384 bytes)
skip= Blocks to skip (for resume)
- Precise control over read position
Upload with Append
dd of=/remote/path/file.txt bs=16384 seek=10 conv=notrunc
of= Output file path
seek= Blocks to seek (for resume)
conv=notrunc Don't truncate existing file
- Good for large file resume
Method 3: Base64 Encoding
Most robust fallback for restrictive environments:
Download with Base64
base64 -w 0 /remote/path/file.txt
- Encodes binary to ASCII
-w 0 No line wrapping (single line)
- Plugin decodes base64 locally
- Handles any file type safely
Upload with Base64
base64 -d > /remote/path/file.txt
- Plugin encodes file to base64
- Shell decodes and writes to file
-d Decode mode
- Works through any text-only channel
Resume Strategies
Base64 Resume Alignment
Base64 encoding has special handling for resume:
- Base64 encodes 3 bytes → 4 characters
- Resume must align to 3-byte boundaries
- Plugin calculates correct skip position
- Ensures decoded output is byte-perfect
Resume Example
# File is 10000 bytes, already have 3000
# 3000 bytes = 1000 blocks of 3 bytes
# Base64: 1000 * 4 = 4000 characters to skip
base64 -w 0 file.txt | tail -c +4001 | base64 -d >> partial.file
Directory Operations
List Directory
ls -la /remote/path/
- Detailed listing with permissions
- Plugin parses output for file info
- Handles spaces in filenames
Create Directory
mkdir -p /remote/path/newdir
-p Create parent directories
- Recursive creation
- No error if exists
Remove File
rm -f /remote/path/file.txt
-f Force, no prompt
- Silent success
Remove Directory
rm -rf /remote/path/olddir
-r Recursive
-f Force
- Use with caution
Rename/Move
mv /remote/path/old.txt /remote/path/new.txt
- Works across same filesystem
- Atomic on same partition
Get File Info
stat /remote/path/file.txt
- Shows size, permissions, timestamps
- Plugin parses for metadata
Shell Detection
Available Commands
Plugin tests for command availability:
which cat
which dd
which base64
which ls
which mkdir
which rm
which mv
which stat
Fallback Order
- Try SFTP native operations
- Try SCP commands
- Try shell cat/dd
- Try base64 encoding
- Last resort: chunked base64
SCP Shell Mode
SCP with Shell Fallback
Some hosts need shell for SCP operations:
SCP Send
scp -t /remote/path/file.txt
-t Target mode (receive file)
- Plugin sends file metadata + content
- Server acknowledges each step
SCP Receive
scp -f /remote/path/file.txt
-f From mode (send file)
- Server sends metadata + content
- Plugin acknowledges receipt
SCP Shell Protocol
# Plugin sends:
T1234567890 0 1234567890 0 (timestamps)
C0644 1234 file.txt (file mode, size, name)
[...file content...]
\0 (null terminator)
# Server responds with:
\0 (OK)
\1error (Error)
\2fatal error (Fatal)
Error Handling
Command Not Found
- Plugin tries alternative commands
- Example: no base64 → try uuencode
- Last resort: report error
Permission Denied
- Check remote file permissions
- Verify user has write access
- Try alternative location
Command Timeout
- Default timeout: 20 seconds
- Large files may need more time
- Plugin sends keepalive during transfer
Partial Transfer
- Connection interrupted mid-transfer
- Plugin detects incomplete file
- Resume from last good position
- Base64 resume aligned to boundaries
Performance Considerations
Base64 Overhead
- Base64 increases size by ~33%
- Encoding/decoding CPU cost
- Use only when necessary
- Still faster than no transfer at all
Block Size Tuning
- Default: 16384 bytes (16 KB)
- Larger blocks: more efficient
- Smaller blocks: better for slow links
- Auto-tuned based on connection
Latency Impact
- Shell commands round-trip latency
- Pipelining where possible
- Batch small operations
Security Notes
Command Injection Protection
- Filenames properly escaped
- Shell metacharacters quoted
- Path traversal prevented
Shell Quoting
# Filename with spaces:
cat "/remote/path/my file.txt"
# Filename with special chars:
cat '/remote/path/file$var.txt'
Note: Shell fallback prioritizes compatibility over terminal semantics. Some interactive features may not work.
Tip: If shell transfer works but is slow, try enabling compression in SSH settings or use base64 for binary files only.
Back to index