cli/README.md
A modern, feature-rich command-line interface for FastDFS with enhanced usability and productivity features.
The CLI tool is built automatically when you build FastDFS:
cd fastdfs
./make.sh
./make.sh install
The fdfs_cli binary will be installed to /usr/bin (or your configured TARGET_PREFIX/bin).
fdfs_cli [options] <command> [args...]
| Option | Description |
|---|---|
-c <config> | Configuration file path (required) |
-j | Enable JSON output format |
-n | Disable colored output |
-v | Enable verbose mode |
-p <index> | Specify storage path index |
-h | Show help message |
# Upload to default group
fdfs_cli -c /etc/fdfs/client.conf upload /path/to/file.jpg
# Upload to specific group
fdfs_cli -c /etc/fdfs/client.conf upload /path/to/file.jpg group1
# With JSON output
fdfs_cli -c /etc/fdfs/client.conf -j upload /path/to/file.jpg
Output:
Uploading: /path/to/file.jpg (2.45 MB)
Progress [==================================================] 100%
✓ Upload successful!
File ID: group1/M00/00/00/wKgBaGFxxx.jpg
# Download with auto-generated filename
fdfs_cli -c /etc/fdfs/client.conf download group1/M00/00/00/wKgBaGFxxx.jpg
# Download to specific location
fdfs_cli -c /etc/fdfs/client.conf download group1/M00/00/00/wKgBaGFxxx.jpg /tmp/myfile.jpg
Output:
Downloading: group1/M00/00/00/wKgBaGFxxx.jpg
Progress [==================================================] 100%
✓ Download successful!
Saved to: /tmp/myfile.jpg (2.45 MB)
fdfs_cli -c /etc/fdfs/client.conf delete group1/M00/00/00/wKgBaGFxxx.jpg
Output:
✓ File deleted: group1/M00/00/00/wKgBaGFxxx.jpg
fdfs_cli -c /etc/fdfs/client.conf info group1/M00/00/00/wKgBaGFxxx.jpg
Output:
File Information
================
File ID: group1/M00/00/00/wKgBaGFxxx.jpg
Size: 2.45 MB (2568192 bytes)
Created: 2025-11-19 22:30:45
CRC32: 0x12345678
Source IP: 192.168.1.100
Create a file list (files.txt):
/path/to/file1.jpg
/path/to/file2.png
/path/to/file3.pdf
# Comments are supported
/path/to/file4.doc
Run batch upload:
fdfs_cli -c /etc/fdfs/client.conf batch upload files.txt
Output:
Batch upload: 4 files
Batch [==================================================] 100%
Summary: Success=4 Failed=0 Total=4
Batch operations support:
batch upload <file_list> - Upload multiple filesbatch download <file_list> - Download multiple files (list contains file IDs)batch delete <file_list> - Delete multiple files (list contains file IDs)fdfs_cli -c /etc/fdfs/client.conf interactive
Interactive Session:
FastDFS Interactive CLI
Type 'help' for commands, 'exit' to quit
fdfs> help
Commands: upload <file> [group] | download <fid> [dest] | delete <fid> | info <fid> | batch <op> <list> | exit
fdfs> upload test.jpg
Uploading: test.jpg (1.23 MB)
Progress [==================================================] 100%
✓ Upload successful!
File ID: group1/M00/00/00/wKgBaGFxxx.jpg
fdfs> info group1/M00/00/00/wKgBaGFxxx.jpg
File Information
================
File ID: group1/M00/00/00/wKgBaGFxxx.jpg
Size: 1.23 MB (1290240 bytes)
Created: 2025-11-19 22:35:12
CRC32: 0xABCDEF01
Source IP: 192.168.1.100
fdfs> exit
Goodbye!
Enable JSON output with the -j flag for easy integration with scripts and automation tools.
{
"operation": "upload",
"success": true,
"file_id": "group1/M00/00/00/wKgBaGFxxx.jpg"
}
{
"operation": "download",
"success": true,
"file_id": "group1/M00/00/00/wKgBaGFxxx.jpg",
"local": "/tmp/myfile.jpg",
"size": 2568192
}
{
"operation": "info",
"success": true,
"file_id": "group1/M00/00/00/wKgBaGFxxx.jpg",
"size": 2568192,
"timestamp": 1700432445,
"crc32": 305441401,
"source_ip": "192.168.1.100"
}
{
"operation": "upload",
"success": false,
"error_code": 2,
"error": "No such file or directory"
}
{
"operation": "batch_upload",
"total": 10,
"success": 9,
"failed": 1
}
#!/bin/bash
# Upload with error handling
result=$(fdfs_cli -c /etc/fdfs/client.conf -j upload photo.jpg)
if echo "$result" | grep -q '"success":true'; then
file_id=$(echo "$result" | grep -o '"file_id":"[^"]*"' | cut -d'"' -f4)
echo "Uploaded successfully: $file_id"
else
echo "Upload failed"
exit 1
fi
# Generate file list
find /photos -name "*.jpg" > upload_list.txt
# Batch upload
fdfs_cli -c /etc/fdfs/client.conf batch upload upload_list.txt
# With JSON output for logging
fdfs_cli -c /etc/fdfs/client.conf -j batch upload upload_list.txt >> upload_log.json
# Upload and immediately get info
file_id=$(fdfs_cli -c /etc/fdfs/client.conf upload test.jpg | tail -1)
fdfs_cli -c /etc/fdfs/client.conf info "$file_id"
The CLI tool uses the standard FastDFS client configuration file. Example /etc/fdfs/client.conf:
connect_timeout = 30
network_timeout = 60
base_path = /tmp
tracker_server = 192.168.1.100:22122
tracker_server = 192.168.1.101:22122
-j flag provides consistent, parseable output-n flag when piping outputError: Tracker connection failed
tracker_server in config fileError: File not found: /path/to/file
Error: Configuration file required (-c option)
-c option-n for maximum performance| Feature | Original Tools | Modern CLI |
|---|---|---|
| Upload | fdfs_upload_file | fdfs_cli upload |
| Download | fdfs_download_file | fdfs_cli download |
| Delete | fdfs_delete_file | fdfs_cli delete |
| Info | fdfs_file_info | fdfs_cli info |
| Batch | ❌ | ✅ |
| Interactive | ❌ | ✅ |
| Progress Bars | ❌ | ✅ |
| Colored Output | ❌ | ✅ |
| JSON Output | ❌ | ✅ |
| Single Binary | ❌ | ✅ |
Copyright (C) 2008 Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General Public License V3.
Contributions are welcome! Please see the main FastDFS repository for contribution guidelines.