Documentation ¶
Overview ¶
Package sshttp provides functionality that enables some functionality of Go's net/http package to be used with SSH servers using SFTP. MIT Licensed.
Index ¶
Constants ¶
const ( // Protocol is the protocol which identifies SFTP as the proper scheme for // a URL used by this package. Protocol = "sftp" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct { // Embed for interface implementation *sftp.File // contains filtered or unexported fields }
File implements http.File using remote files over SFTP, and is returned by FileSystem's Open method.
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
FileSystem implements http.FileSystem for remote files over SFTP.
func NewFileSystem ¶
func NewFileSystem(host string, config *ssh.ClientConfig) (*FileSystem, error)
NewFileSystem creates a new FileSystem which can access remote files over SFTP. The resulting FileSystem can be used by net/http to provide access to remote files over SFTP, as if they were local. The host parameter specifies the URI to dial and access, and the configuration parameter is used to configure the underlying SSH connection.
A host must be a complete URI, including a protocol segment. For example, sftp://127.0.0.1:22/home/foo dials 127.0.0.1 on port 22, and accesses the /home/foo directory on the host.
func (*FileSystem) Close ¶
func (fs *FileSystem) Close() error
Close closes open SFTP and SSH connections for this FileSystem.
type RoundTripper ¶
type RoundTripper struct {
// contains filtered or unexported fields
}
RoundTripper implements http.RoundTripper, and handles performing a HTTP request over SSH, using SFTP to send a file in response. A RoundTripper can automatically dial SSH hosts when RoundTrip is called, assuming the correct default credentials are provided. If more control is needed, use the Dial method to configure each host on an individual basis.
func NewRoundTripper ¶
func NewRoundTripper(config *ssh.ClientConfig) *RoundTripper
NewRoundTripper accepts a ssh.ClientConfig struct and returns a RoundTripper which can be used by net/http. The configuration parameter is used as the default for any SSH hosts which are not explicitly configured using the Dial method.
func (*RoundTripper) Close ¶
func (rt *RoundTripper) Close() error
Close closes all open SFTP and SSH connections for this RoundTripper.
func (*RoundTripper) Dial ¶
func (rt *RoundTripper) Dial(host string, config *ssh.ClientConfig) error
Dial attempts to dial a SSH connection to the specified host, using the specified SSH client configuration. If the config parameter is nil, the default set by NewRoundTripper will be used.
Dial should be used if more than a single host is being dialed by RoundTripper, so that various SSH client configurations may be used, if needed. For a single host, allowing RoundTripper to lazily dial a host using the default SSH client configuration is typically acceptable.
func (*RoundTripper) RoundTrip ¶
RoundTrip implements http.RoundTripper, and performs a HTTP request over SSH, using SFTP to coordinate the response. If a SSH connection is not already open to the host specified in r.URL.Host, RoundTrip will attempt to lazily dial the host using the default configuration from NewRoundTripper.