sshx

package
v0.0.0-...-24715e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command(ssh *ssh.Client, cmd string) (string, error)

Command executes a command on the remote host and returns the output

func ForEachHost

func ForEachHost(hostConfigs []*Config, fn ExecuteFunc)

ForEachHost iterates over all hosts and executes the given function with SSH connection It handles connection opening/closing and error logging automatically

func ForEachHostWithSFTP

func ForEachHostWithSFTP(hostConfigs []*Config, fn ExecuteWithSFTPFunc)

ForEachHostWithSFTP iterates over all hosts and executes the given function with both SSH and SFTP connections It handles connection opening/closing and error logging automatically

func IsSymlink(sftpClient *sftp.Client, remotePath string) (bool, error)

IsSymlink determines whether the remote path is a symbolic link

func Mkdir

func Mkdir(sftpClient *sftp.Client, remotePath string) error

Mkdir creates a directory on the remote server, creating it if it doesn't exist

func Open

func Open(cfg *Config) (*ssh.Client, error)

Open establishes an SSH connection

func OpenSftp

func OpenSftp(client *ssh.Client) (*sftp.Client, error)
func ReadLink(sftpClient *sftp.Client, remotePath string) (string, error)

ReadLink reads the actual path that the remote symbolic link points to

func RemoteExists

func RemoteExists(sftpClient *sftp.Client, remotePath string) bool

RemoteExists determines whether the remote path exists

func UploadFile

func UploadFile(sftpClient *sftp.Client, localPath, remotePath string) error

UploadFile uploads a local file to remote

Types

type Config

type Config struct {
	User       string        `yaml:"user"`       // Login username
	Password   string        `yaml:"password"`   // Password, optional
	Host       string        `yaml:"host"`       // Remote host address
	Port       int           `yaml:"port"`       // Port, default 22
	KeyPath    string        `yaml:"keyPath"`    // Private key path, optional
	Passphrase string        `yaml:"passphrase"` // Private key password, optional
	Timeout    time.Duration `yaml:"timeout"`    // SSH connection timeout
}

Config SSH connection configuration

func Load

func Load(cmd *cli.Command) ([]*Config, error)

type ExecuteFunc

type ExecuteFunc func(*SSHClient, *Config) error

ExecuteFunc defines a function that executes with an SSH client

type ExecuteWithSFTPFunc

type ExecuteWithSFTPFunc func(*SFTPClient, *SSHClient, *Config) error

ExecuteWithSFTPFunc defines a function that executes with both SSH and SFTP clients

type FileInfo

type FileInfo struct {
	FileInfo os.FileInfo // Detailed file information
	Path     string      // Complete file path
	Name     string      // File name
	IsLink   bool        // Whether it's a soft link (current version)
}

FileInfo encapsulates remote file information

func List

func List(sftpClient *sftp.Client, remotePath, linkPath string) ([]FileInfo, error)

List lists all file information under the remote directory and marks the current version link

type SFTPClient

type SFTPClient = sftp.Client

SFTPClient is an alias for sftp.Client

type SSHClient

type SSHClient = ssh.Client

SSHClient is an alias for ssh.Client

Source Files

  • load.go
  • manager.go
  • sftp.go
  • ssh.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址