package main

import (
	"flag"
	"fmt"
	"log"
)

// 定义命令行参数
var (
	h *string
	u *string
	p *int
	e *string
	k *string
	c *string
	l *string
	r *string
)

// SSH 配置结构体
type SSHConfig struct {
	Host       string
	Port       int
	User       string
	Password   string
	PrivateKey string
	Passphrase string
}

func argv() {

	h = flag.String("h", "127.0.0.1", "SSH server hostname or IP")
	p = flag.Int("p", 22, "SSH server port")
	u = flag.String("u", "root", "SSH username")
	e = flag.String("e", "", "SSH password")
	k = flag.String("k", "", "Path to SSH private key file")
	c = flag.String("c", ":", "Command to execute on the remote server")
	l = flag.String("l", "", "Local file path to upload")
	r = flag.String("r", "", "Remote file path to upload")

	// 解析命令行参数
	flag.Parse()
}

func main() {
	argv()
	var err error
	var output string

	if *r == "" || *l == "" {
		fmt.Println("No file specified, no upload")
	} else {
		_sftp()
	}

	output, err = _ssh()
	if err != nil {
		log.Fatalf("Error: %v", err)
	}
	fmt.Printf("Command output:\n%s", output)

	/*
		// 本地执行命令
		command := "ls -l"
		output, err = localExecSSHCommand(command, 360*time.Second)
		if err != nil {
			fmt.Printf("Error: %v\n", err)
		} else {
			fmt.Printf("Command output:\n%s", output)
		}
	*/

}
