Documentation
¶
Overview ¶
Package sshclient implements an SSH client.
Index ¶
- type Client
- 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) 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
- type RemoteShell
- type SftpOption
- type StatVFS
- type TerminalConfig
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
}
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) Sftp ¶ added in v1.2.0
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 ¶ added in v1.1.0
UnderlyingClient get the underlying client.
type RemoteFile ¶ added in v1.2.0
RemoteFile represents a remote file.
type RemoteFileSystem ¶ added in v1.2.0
type RemoteFileSystem struct {
// contains filtered or unexported fields
}
RemoteFileSystem represents a remoote file system.
func (*RemoteFileSystem) Chmod ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Chmod(path string, mode os.FileMode) error
func (*RemoteFileSystem) Chown ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Chown(path string, uid, gid int) error
func (*RemoteFileSystem) Close ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Close() error
Close closes the SFTP session.
func (*RemoteFileSystem) Create ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Create(path string) (*RemoteFile, error)
func (*RemoteFileSystem) Download ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Download(remotePath, hostPath string) (retErr error)
func (*RemoteFileSystem) Getwd ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Getwd() (string, error)
func (*RemoteFileSystem) Glob ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Glob(pattern string) (matches []string, err error)
func (*RemoteFileSystem) Link ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Link(oldname, newname string) error
func (*RemoteFileSystem) Lstat ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Lstat(path string) (os.FileInfo, error)
func (*RemoteFileSystem) Mkdir ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Mkdir(path string) error
func (*RemoteFileSystem) MkdirAll ¶ added in v1.2.0
func (rfs *RemoteFileSystem) MkdirAll(path string) error
func (*RemoteFileSystem) Open ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Open(path string) (*RemoteFile, error)
func (*RemoteFileSystem) OpenFile ¶ added in v1.2.0
func (rfs *RemoteFileSystem) OpenFile(path string, f int) (*RemoteFile, error)
func (*RemoteFileSystem) PosixRename ¶ added in v1.2.0
func (rfs *RemoteFileSystem) PosixRename(oldname, newname string) error
func (*RemoteFileSystem) ReadDir ¶ added in v1.2.0
func (rfs *RemoteFileSystem) ReadDir(path string) ([]os.FileInfo, error)
func (*RemoteFileSystem) ReadFile ¶ added in v1.2.0
func (rfs *RemoteFileSystem) ReadFile(name string) ([]byte, error)
func (*RemoteFileSystem) ReadLink ¶ added in v1.2.0
func (rfs *RemoteFileSystem) ReadLink(path string) (string, error)
func (*RemoteFileSystem) RealPath ¶ added in v1.2.0
func (rfs *RemoteFileSystem) RealPath(path string) (string, error)
func (*RemoteFileSystem) Remove ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Remove(path string) error
func (*RemoteFileSystem) RemoveDirectory ¶ added in v1.2.0
func (rfs *RemoteFileSystem) RemoveDirectory(path string) error
func (*RemoteFileSystem) Rename ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Rename(oldname, newname string) error
func (*RemoteFileSystem) Stat ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Stat(path string) (os.FileInfo, error)
func (*RemoteFileSystem) StatVFS ¶ added in v1.2.0
func (rfs *RemoteFileSystem) StatVFS(path string) (*StatVFS, error)
func (*RemoteFileSystem) Symlink ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Symlink(oldname, newname string) error
func (*RemoteFileSystem) Truncate ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Truncate(path string, size int64) error
func (*RemoteFileSystem) Upload ¶ added in v1.2.0
func (rfs *RemoteFileSystem) Upload(hostPath, remotePath string) (retErr error)
func (*RemoteFileSystem) Wait ¶ added in v1.2.0
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) 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 SftpOption ¶ added in v1.2.0
type SftpOption func(*remoteFileSystemConfig)
func SftpMaxConcurrentRequestsPerFile ¶ added in v1.2.0
func SftpMaxConcurrentRequestsPerFile(n int) SftpOption
func SftpMaxPacket ¶ added in v1.2.0
func SftpMaxPacket(size int) SftpOption
func SftpUseConcurrentReads ¶ added in v1.2.0
func SftpUseConcurrentReads(value bool) SftpOption
func SftpUseConcurrentWrites ¶ added in v1.2.0
func SftpUseConcurrentWrites(value bool) SftpOption
func SftpUseFstat ¶ added in v1.2.0
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.