Documentation ¶
Overview ¶
Package ssh provide a wrapper for golang.org/x/crypto/ssh.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client for SSH connection.
func NewClient ¶
func NewClient(cfg *ClientConfig) (cl *Client, err error)
NewClient create a new SSH connection using predefined configuration.
func (*Client) Get ¶
Get copy file from remote into local storage.
The local file should be use the absolute path, or relative to the file in ClientConfig.WorkingDir.
type ClientConfig ¶
type ClientConfig struct { // Environments contains system environment variables that will be // passed to Execute(). Environments map[string]string // WorkingDir contains the directory where the SSH client started. // This value is required when client want to copy file from/to // remote. // This field is optional, default to current working directory from // os.Getwd() or user's home directory. WorkingDir string // PrivateKeyFile contains path to private key file. // This field is optional, default to ".ssh/id_rsa" in user's home // directory. PrivateKeyFile string // RemoteUser contains the user name in remote system. // This field is mandatory. RemoteUser string // RemoteHost contains the IP address or host name of remote system. // This field is mandatory. RemoteHost string // RemotePort contains the port address of remote SSH server. // This field is optional, default to 22. RemotePort int // contains filtered or unexported fields }
ClientConfig contains the configuration to create SSH connection and the environment where the SSH program started.
Example ¶
cfg := &ClientConfig{ WorkingDir: "/tmp", PrivateKeyFile: "testdata/example.pem", RemoteUser: "hodor", RemoteHost: "127.0.0.1", } err := cfg.initialize() if err != nil { log.Fatal(err) } fmt.Printf("WorkingDir: %s\n", cfg.WorkingDir) fmt.Printf("PrivateKeyFile: %s\n", cfg.PrivateKeyFile) fmt.Printf("RemoteUser: %s\n", cfg.RemoteUser) fmt.Printf("RemoteHost: %s\n", cfg.RemoteHost) fmt.Printf("RemotePort: %d\n", cfg.RemotePort) fmt.Printf("remoteAddr: %s\n", cfg.remoteAddr)
Output: WorkingDir: /tmp PrivateKeyFile: testdata/example.pem RemoteUser: hodor RemoteHost: 127.0.0.1 RemotePort: 22 remoteAddr: 127.0.0.1:22
Click to show internal directories.
Click to hide internal directories.