Skip to content

xxddccaa/xds

Repository files navigation

XDS - Convenient SSH Server Management Tool

XDS is a command-line tool written in Go for quickly managing SSH server connections and file transfers. It reads your local ~/.ssh/config configuration, allowing you to quickly upload and download files without typing complete scp commands every time.

Features

  • 📋 List Servers: Automatically reads ~/.ssh/config and lists all configured servers
  • ⚙️ Set Default Server: Set a default server for subsequent operations
  • ⬆️ Quick Upload: One-click file upload to specified server directory
  • ⬇️ Quick Download: One-click file download from server to local
  • 🔐 Auto Authentication: Supports SSH key and SSH agent automatic authentication
  • 📊 Progress Display: Real-time display of transfer progress, speed, and remaining time
  • 🎯 Smart Path: Automatically detects directories, similar to scp behavior
  • 🔄 Rsync Integration: Sync files using rsync with resume capability

Installation

Compile from Source

cd xds
make

The compiled binary will be located at bin/xds.

Install to System

make install

This will install xds to /usr/local/bin/.

Usage

1. List All Servers

xds list

This displays all servers configured in ~/.ssh/config and marks the current default server (if any).

Example output:

Configured servers:

* [1] aliyun_DSW3
     Address: example.com
     User: root
     Port: 22
     Key: ~/.ssh/id_rsa

 [2] test_server
     Address: test.example.com
     User: admin

Default server: aliyun_DSW3 (use 'xds set <server>' to change)

2. Set Default Server

xds set <server_name>

Example:

xds set aliyun_DSW3

After setting, subsequent upload, download, and sync commands will automatically use this default server if -s flag is not specified.

3. Upload Files

xds upload <local_file_path> <remote_file_path>

Using default server:

xds upload ./test.txt /data/test.txt

Upload to directory (automatically uses filename):

xds upload ./test.txt /data/
# Automatically uploads to /data/test.txt with progress bar

Specify server (temporarily override default):

xds upload -s test_server ./test.txt /data/test.txt

Progress display example:

Uploading test.txt [===================>        ] 65% | 3.2 MB/5.0 MB | 1.5 MB/s | 1s

4. Download Files

xds download <remote_file_path> <local_file_path>

Using default server:

xds download /data/test.txt ./test.txt

Download to current directory (automatically uses remote filename):

xds download /data/test.txt .

Specify server:

xds download -s test_server /data/test.txt ./test.txt

5. Sync Files (rsync)

xds sync <local_path> <remote_path>

Basic sync:

xds sync ./local_dir /remote/dir

Sync with options:

# Dry run (preview what will be transferred)
xds sync --dry-run ./local /remote/

# Delete extraneous files from destination
xds sync --delete ./local /remote/

# Exclude patterns
xds sync --exclude "*.log" --exclude "*.tmp" ./local /remote/

# Bandwidth limiting
xds sync --limit 1m ./large_dir /remote/dir

# Verbose output
xds sync -v ./local /remote/

Note: The sync command uses rsync, which must be installed on your system:

  • macOS: brew install rsync
  • Ubuntu/Debian: sudo apt-get install rsync
  • CentOS/RHEL: sudo yum install rsync

SSH Configuration Requirements

XDS reads the ~/.ssh/config file to get server configurations. Ensure your SSH configuration format is correct:

Host aliyun_DSW3
    HostName example.com
    User root
    Port 22
    IdentityFile ~/.ssh/id_rsa

Important Notes:

  • The name after Host is the server name you use in XDS
  • IdentityFile is optional; if not specified, XDS will try to use SSH agent
  • Ensure your SSH key has been added to the target server or SSH agent is configured

Configuration File

XDS saves your default server setting in ~/.xds/config.json:

{
  "default_server": "aliyun_DSW3"
}

Complete Usage Examples

# 1. View all servers
xds list

# 2. Set default server
xds set aliyun_DSW3

# 3. Upload file
xds upload ./myfile.txt /data/myfile.txt

# 4. Download file
xds download /data/result.txt ./result.txt

# 5. Sync directory
xds sync ./local_project /remote/project

# 6. Temporarily use another server for upload
xds upload -s test_server ./test.txt /tmp/test.txt

Error Handling

  • If no default server is set and -s flag is not used, XDS will prompt you to set a default server
  • If server configuration doesn't exist, XDS will display an error and suggest using xds list to view available servers
  • If SSH connection fails, check your SSH configuration and network connection
  • If authentication fails, ensure your SSH key is correctly configured or SSH agent is running

Development

Project Structure

xds/
├── cmd/
│   └── xds/
│       └── main.go          # Main program entry
├── pkg/
│   ├── config/              # Configuration management
│   │   └── config.go
│   ├── ssh/                 # SSH configuration parsing
│   │   └── sshconfig.go
│   ├── sftp/                # SFTP file transfer
│   │   └── sftp.go
│   ├── rsync/               # Rsync integration
│   │   └── rsync.go
│   └── transfer/            # Transfer utilities (resume, sync)
│       ├── resume.go
│       └── sync.go
├── Makefile                 # Build script
├── go.mod                   # Go module definition
└── README.md               # This document

Dependencies

  • github.com/alecthomas/kingpin/v2 - Command-line argument parsing
  • github.com/pkg/sftp - SFTP client
  • golang.org/x/crypto/ssh - SSH client
  • github.com/schollz/progressbar/v3 - Progress bar display

Roadmap

See ROADMAP.md for planned features including:

  • Resume interrupted transfers
  • Batch operations
  • Remote command execution
  • Directory operations
  • And more...

License

MIT License

Contributing

Welcome to submit Issues and Pull Requests!

About

本地和远程服务器的文件操作

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors