Documentation ¶
Overview ¶
Package sshclient implements an SSH client.
Index ¶
- Constants
- func GetPerm(f *os.File) (perm string)
- type Client
- func (c *Client) Close() error
- func (c *Client) Cmd(cmd string) *RemoteScript
- func (c *Client) Download(remotePath string, localPath string) (err error)
- func (c *Client) NewSftp(opts ...sftp.ClientOption) (*sftp.Client, error)
- func (c *Client) Script(script string) *RemoteScript
- func (c *Client) ScriptFile(fname string) *RemoteScript
- func (c *Client) Shell() *RemoteShell
- func (c *Client) Terminal(config *TerminalConfig) *RemoteShell
- func (c *Client) UnderlyingClient() *ssh.Client
- func (c *Client) Upload(localPath string, remotePath string) (err error)
- type RemoteScript
- type RemoteShell
- type Scp
- type TerminalConfig
Constants ¶
const ( SCP_PUSH_BEGIN_FILE = "C" SCP_PUSH_BEGIN_FOLDER = "D" SCP_PUSH_BEGIN_END_FOLDER = "0" SCP_PUSH_END_FOLDER = "E" SCP_PUSH_END = "\x00" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client implements an SSH client that supports running commands and scripts remotely.
func Dial ¶
func Dial(network, addr string, config *ssh.ClientConfig) (*Client, error)
Dial starts a client connection to the given SSH server. This wraps ssh.Dial.
func DialWithKey ¶
DialWithKey starts a client connection to the given SSH server with key authmethod.
func DialWithKeyWithPassphrase ¶
DialWithKeyWithPassphrase same as DialWithKey but with a passphrase to decrypt the private key
func DialWithPasswd ¶
DialWithPasswd starts a client connection to the given SSH server with passwd authmethod.
func (*Client) Cmd ¶
func (c *Client) Cmd(cmd string) *RemoteScript
Cmd creates a RemoteScript that can run the command on the client. The cmd string is split on newlines and each line is executed separately.
func (*Client) Script ¶
func (c *Client) Script(script string) *RemoteScript
Script creates a RemoteScript that can run the script on the client.
func (*Client) ScriptFile ¶
func (c *Client) ScriptFile(fname string) *RemoteScript
ScriptFile creates a RemoteScript that can read a local script file and run it remotely on the client.
func (*Client) Shell ¶
func (c *Client) Shell() *RemoteShell
Shell create a noninteractive shell on client.
func (*Client) Terminal ¶
func (c *Client) Terminal(config *TerminalConfig) *RemoteShell
Terminal create an interactive shell on client.
func (*Client) UnderlyingClient ¶
UnderlyingClient get the underlying client.
type RemoteScript ¶
type RemoteScript struct {
// contains filtered or unexported fields
}
A RemoteScript represents script that can be run remotely.
func (*RemoteScript) Cmd ¶
func (rs *RemoteScript) Cmd(cmd string) *RemoteScript
Cmd appends a command to the RemoteScript.
func (*RemoteScript) Output ¶
func (rs *RemoteScript) Output() ([]byte, error)
Output runs the script on the client and returns its standard output.
func (*RemoteScript) Run ¶
func (rs *RemoteScript) Run() error
Run runs the script on the client.
The returned error is nil if the command runs, has no problems copying stdin, stdout, and stderr, and exits with a zero exit status.
func (*RemoteScript) SetStdio ¶
func (rs *RemoteScript) SetStdio(stdout, stderr io.Writer) *RemoteScript
SetStdio specifies where its standard output and error data will be written.
func (*RemoteScript) SmartOutput ¶
func (rs *RemoteScript) SmartOutput() ([]byte, error)
SmartOutput runs the script on the client. On success, its standard ouput is returned. On error, its standard error is returned.
type RemoteShell ¶
type RemoteShell struct {
// contains filtered or unexported fields
}
A RemoteShell represents a login shell on the client.
func (*RemoteShell) SetStdio ¶
func (rs *RemoteShell) SetStdio(stdin io.Reader, stdout, stderr io.Writer) *RemoteShell
SetStdio specifies where the its standard output and error data will be written.
func (*RemoteShell) Start ¶
func (rs *RemoteShell) Start() error
Start starts a remote shell on client.
type Scp ¶
type Scp struct {
// contains filtered or unexported fields
}
type TerminalConfig ¶
type TerminalConfig struct { Term string Height int Weight int Modes ssh.TerminalModes }
A TerminalConfig represents the configuration for an interactive shell session.