ssh.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //go:build !plan9
  2. package sftp
  3. import "io"
  4. // Interfaces for ssh client and session implemented in ssh_internal.go and ssh_external.go
  5. // An interface for an ssh client to abstract over internal ssh library and external binary
  6. type sshClient interface {
  7. // Wait blocks until the connection has shut down, and returns the
  8. // error causing the shutdown.
  9. Wait() error
  10. // SendKeepAlive sends a keepalive message to keep the connection open
  11. SendKeepAlive()
  12. // Close the connection
  13. Close() error
  14. // NewSession opens a new sshSession for this sshClient. (A
  15. // session is a remote execution of a program.)
  16. NewSession() (sshSession, error)
  17. // CanReuse indicates if this client can be reused
  18. CanReuse() bool
  19. }
  20. // An interface for an ssh session to abstract over internal ssh library and external binary
  21. type sshSession interface {
  22. // Setenv sets an environment variable that will be applied to any
  23. // command executed by Shell or Run.
  24. Setenv(name, value string) error
  25. // Start runs cmd on the remote host. Typically, the remote
  26. // server passes cmd to the shell for interpretation.
  27. // A Session only accepts one call to Run, Start or Shell.
  28. Start(cmd string) error
  29. // StdinPipe returns a pipe that will be connected to the
  30. // remote command's standard input when the command starts.
  31. StdinPipe() (io.WriteCloser, error)
  32. // StdoutPipe returns a pipe that will be connected to the
  33. // remote command's standard output when the command starts.
  34. // There is a fixed amount of buffering that is shared between
  35. // stdout and stderr streams. If the StdoutPipe reader is
  36. // not serviced fast enough it may eventually cause the
  37. // remote command to block.
  38. StdoutPipe() (io.Reader, error)
  39. // RequestSubsystem requests the association of a subsystem
  40. // with the session on the remote host. A subsystem is a
  41. // predefined command that runs in the background when the ssh
  42. // session is initiated
  43. RequestSubsystem(subsystem string) error
  44. // Run runs cmd on the remote host. Typically, the remote
  45. // server passes cmd to the shell for interpretation.
  46. // A Session only accepts one call to Run, Start, Shell, Output,
  47. // or CombinedOutput.
  48. Run(cmd string) error
  49. // Close the session
  50. Close() error
  51. // Set the stdout
  52. SetStdout(io.Writer)
  53. // Set the stderr
  54. SetStderr(io.Writer)
  55. }