Documentation ¶
Overview ¶
Package sshclient implements an SSH client.
Index ¶
- func WithEnvs(envs map[string]string) func(*Client) error
- type Client
- func Dial(network, addr string, config *ssh.ClientConfig, options ...func(*Client) error) (*Client, error)
- func DialWithKey(addr, user, keyfile string) (*Client, error)
- func DialWithKeyWithPassphrase(addr, user, keyfile string, passphrase string) (*Client, error)
- func DialWithPasswd(addr, user, passwd string) (*Client, error)
- func (c *Client) Close() error
- func (c *Client) Cmd(cmd string) *RemoteScript
- func (c *Client) Dial(network, addr string, config *ssh.ClientConfig) (*Client, error)
- func (c *Client) DialWithKey(addr, user, keyfile string) (*Client, error)
- func (c *Client) DialWithKeyWithPassphrase(addr, user, keyfile, passphrase string) (*Client, error)
- func (c *Client) DialWithPasswd(addr, user, passwd string) (*Client, error)
- func (c *Client) Script(script string) *RemoteScript
- func (c *Client) ScriptFile(fname string) *RemoteScript
- func (c *Client) Sftp(opts ...SftpOption) *RemoteFileSystem
- func (c *Client) Shell() *RemoteShell
- func (c *Client) Terminal(config *TerminalConfig) *RemoteShell
- func (c *Client) UnderlyingClient() *ssh.Client
- type RemoteFile
- type RemoteFileSystem
- func (rfs *RemoteFileSystem) Chmod(path string, mode os.FileMode) error
- func (rfs *RemoteFileSystem) Chown(path string, uid, gid int) error
- func (rfs *RemoteFileSystem) Chtimes(path string, atime time.Time, mtime time.Time) error
- func (rfs *RemoteFileSystem) Close() error
- func (rfs *RemoteFileSystem) Create(path string) (*RemoteFile, error)
- func (rfs *RemoteFileSystem) Download(remotePath, hostPath string) (retErr error)
- func (rfs *RemoteFileSystem) Getwd() (string, error)
- func (rfs *RemoteFileSystem) Glob(pattern string) (matches []string, err error)
- func (rfs *RemoteFileSystem) Link(oldname, newname string) error
- func (rfs *RemoteFileSystem) Lstat(path string) (os.FileInfo, error)
- func (rfs *RemoteFileSystem) Mkdir(path string) error
- func (rfs *RemoteFileSystem) MkdirAll(path string) error
- func (rfs *RemoteFileSystem) Open(path string) (*RemoteFile, error)
- func (rfs *RemoteFileSystem) OpenFile(path string, f int) (*RemoteFile, error)
- func (rfs *RemoteFileSystem) PosixRename(oldname, newname string) error
- func (rfs *RemoteFileSystem) ReadDir(path string) ([]os.FileInfo, error)
- func (rfs *RemoteFileSystem) ReadFile(name string) ([]byte, error)
- func (rfs *RemoteFileSystem) ReadLink(path string) (string, error)
- func (rfs *RemoteFileSystem) RealPath(path string) (string, error)
- func (rfs *RemoteFileSystem) Remove(path string) error
- func (rfs *RemoteFileSystem) RemoveDirectory(path string) error
- func (rfs *RemoteFileSystem) Rename(oldname, newname string) error
- func (rfs *RemoteFileSystem) Stat(path string) (os.FileInfo, error)
- func (rfs *RemoteFileSystem) StatVFS(path string) (*StatVFS, error)
- func (rfs *RemoteFileSystem) Symlink(oldname, newname string) error
- func (rfs *RemoteFileSystem) Truncate(path string, size int64) error
- func (rfs *RemoteFileSystem) Upload(hostPath, remotePath string) (retErr error)
- func (rfs *RemoteFileSystem) Wait() error
- func (rfs *RemoteFileSystem) Walk(root string) (*fs.Walker, error)
- func (rfs *RemoteFileSystem) WriteFile(name string, data []byte, perm os.FileMode) error
- type RemoteScript
- func (rs *RemoteScript) Cmd(cmd string) *RemoteScript
- func (rs *RemoteScript) NewSession() (*ssh.Session, error)
- func (rs *RemoteScript) Output(s *ssh.Session) ([]byte, error)
- func (rs *RemoteScript) Run(s *ssh.Session) error
- func (rs *RemoteScript) SetStdio(stdout, stderr io.Writer) *RemoteScript
- func (rs *RemoteScript) SmartOutput(s *ssh.Session) ([]byte, error)
- type RemoteShell
- type SftpOption
- type StatVFS
- type TerminalConfig
Constants ¶
This section is empty.
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, options ...func(*Client) error) (*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) DialWithKey ¶
DialWithKey initiates a Client to the addr from the remote host with key authmethod.
func (*Client) DialWithKeyWithPassphrase ¶
DialWithKeyWithPassphrase same as DialWithKey but with a passphrase to decrypt the private key
func (*Client) DialWithPasswd ¶
DialWithPasswd initiates a Client to the addr from the remote host with passwd authmethod.
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) Sftp ¶
func (c *Client) Sftp(opts ...SftpOption) *RemoteFileSystem
Sftp creates a new SFTP session, using zero or more option functions.
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 a interactive shell on client.
func (*Client) UnderlyingClient ¶
UnderlyingClient get the underlying client.
type RemoteFileSystem ¶
type RemoteFileSystem struct {
// contains filtered or unexported fields
}
RemoteFileSystem represents a remoote file system.
func (*RemoteFileSystem) Chmod ¶
func (rfs *RemoteFileSystem) Chmod(path string, mode os.FileMode) error
func (*RemoteFileSystem) Chown ¶
func (rfs *RemoteFileSystem) Chown(path string, uid, gid int) error
func (*RemoteFileSystem) Close ¶
func (rfs *RemoteFileSystem) Close() error
Close closes the SFTP session.
func (*RemoteFileSystem) Create ¶
func (rfs *RemoteFileSystem) Create(path string) (*RemoteFile, error)
func (*RemoteFileSystem) Download ¶
func (rfs *RemoteFileSystem) Download(remotePath, hostPath string) (retErr error)
func (*RemoteFileSystem) Getwd ¶
func (rfs *RemoteFileSystem) Getwd() (string, error)
func (*RemoteFileSystem) Glob ¶
func (rfs *RemoteFileSystem) Glob(pattern string) (matches []string, err error)
func (*RemoteFileSystem) Link ¶
func (rfs *RemoteFileSystem) Link(oldname, newname string) error
func (*RemoteFileSystem) Lstat ¶
func (rfs *RemoteFileSystem) Lstat(path string) (os.FileInfo, error)
func (*RemoteFileSystem) Mkdir ¶
func (rfs *RemoteFileSystem) Mkdir(path string) error
func (*RemoteFileSystem) MkdirAll ¶
func (rfs *RemoteFileSystem) MkdirAll(path string) error
func (*RemoteFileSystem) Open ¶
func (rfs *RemoteFileSystem) Open(path string) (*RemoteFile, error)
func (*RemoteFileSystem) OpenFile ¶
func (rfs *RemoteFileSystem) OpenFile(path string, f int) (*RemoteFile, error)
func (*RemoteFileSystem) PosixRename ¶
func (rfs *RemoteFileSystem) PosixRename(oldname, newname string) error
func (*RemoteFileSystem) ReadDir ¶
func (rfs *RemoteFileSystem) ReadDir(path string) ([]os.FileInfo, error)
func (*RemoteFileSystem) ReadFile ¶
func (rfs *RemoteFileSystem) ReadFile(name string) ([]byte, error)
func (*RemoteFileSystem) ReadLink ¶
func (rfs *RemoteFileSystem) ReadLink(path string) (string, error)
func (*RemoteFileSystem) RealPath ¶
func (rfs *RemoteFileSystem) RealPath(path string) (string, error)
func (*RemoteFileSystem) Remove ¶
func (rfs *RemoteFileSystem) Remove(path string) error
func (*RemoteFileSystem) RemoveDirectory ¶
func (rfs *RemoteFileSystem) RemoveDirectory(path string) error
func (*RemoteFileSystem) Rename ¶
func (rfs *RemoteFileSystem) Rename(oldname, newname string) error
func (*RemoteFileSystem) StatVFS ¶
func (rfs *RemoteFileSystem) StatVFS(path string) (*StatVFS, error)
func (*RemoteFileSystem) Symlink ¶
func (rfs *RemoteFileSystem) Symlink(oldname, newname string) error
func (*RemoteFileSystem) Truncate ¶
func (rfs *RemoteFileSystem) Truncate(path string, size int64) error
func (*RemoteFileSystem) Upload ¶
func (rfs *RemoteFileSystem) Upload(hostPath, remotePath string) (retErr error)
func (*RemoteFileSystem) Wait ¶
func (rfs *RemoteFileSystem) Wait() error
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) NewSession ¶
func (rs *RemoteScript) NewSession() (*ssh.Session, error)
func (*RemoteScript) Output ¶
func (rs *RemoteScript) Output(s *ssh.Session) ([]byte, error)
Output runs the script on the client and returns its standard output.
func (*RemoteScript) Run ¶
func (rs *RemoteScript) Run(s *ssh.Session) 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(s *ssh.Session) ([]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 SftpOption ¶
type SftpOption func(*remoteFileSystemConfig)
func SftpMaxConcurrentRequestsPerFile ¶
func SftpMaxConcurrentRequestsPerFile(n int) SftpOption
func SftpMaxPacket ¶
func SftpMaxPacket(size int) SftpOption
func SftpUseConcurrentReads ¶
func SftpUseConcurrentReads(value bool) SftpOption
func SftpUseConcurrentWrites ¶
func SftpUseConcurrentWrites(value bool) SftpOption
func SftpUseFstat ¶
func SftpUseFstat(value bool) SftpOption
type TerminalConfig ¶
type TerminalConfig struct { Term string Height int Weight int Modes ssh.TerminalModes }
A TerminalConfig represents the configuration for an interactive shell session.