Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAuthError ¶
NewAuthError returns a pointer to a new AuthError from the underlying |e| error message.
Types ¶
type AsyncUpload ¶
type AsyncUpload interface { // Bytes returns the number of bytes copied to the SFTP destination. Bytes() int64 // Close closes SFTP connection used for the upload. Close must be called // when the upload is complete to prevent memory leaks. Close() error // Done returns a channel that receives a true value when the upload is // complete. A done signal should not be sent on error. Done() chan bool // Done returns a channel that receives an error if the upload encounters // an error. Err() chan error // Write implements the io.Writer interface and adds len(p) to the count of // bytes uploaded. Write(p []byte) (int, error) }
AsyncUpload provides information about an upload happening asynchronously in a separate goroutine.
type AsyncUploadImpl ¶
type AsyncUploadImpl struct {
// contains filtered or unexported fields
}
AsyncUploadImpl provides an asynchronous upload implementation.
func NewAsyncUpload ¶
func NewAsyncUpload(conn *connection) AsyncUploadImpl
NewAsyncUpload returns an initialized AsyncUploadImpl struct that wraps the underlying SFTP connection.
func (*AsyncUploadImpl) Bytes ¶
func (u *AsyncUploadImpl) Bytes() int64
Bytes returns the current number of bytes uploaded.
func (*AsyncUploadImpl) Close ¶
func (u *AsyncUploadImpl) Close() error
Close closes SFTP connection used for the upload. Close must be called when the upload is complete to prevent memory leaks.
func (*AsyncUploadImpl) Done ¶
func (u *AsyncUploadImpl) Done() chan bool
Done returns a done channel that receives a true value when the upload is complete.
func (*AsyncUploadImpl) Err ¶
func (u *AsyncUploadImpl) Err() chan error
Error returns an error channel that receives an error if the upload encounters an error.
type AuthError ¶
type AuthError struct {
Message string
}
AuthError represents an SFTP authentication error.
type Client ¶
type Client interface { // Delete removes dest from the SFTP server. Delete(ctx context.Context, dest string) error // Upload asynchronously copies data from the src reader to the specified // dest on the SFTP server. UploadFile(ctx context.Context, src io.Reader, dest string) (remotePath string, upload AsyncUpload, err error) UploadDirectory(ctx context.Context, srcPath string) (remotePath string, upload AsyncUpload, err error) }
A Client manages the transmission of data over SFTP.
Implementations of the Client interface handle the connection details, authentication, and other intricacies associated with different SFTP servers and protocols.
type Config ¶
type Config struct { // Host address, e.g. 127.0.0.1 (default), sftp.example.org. Host string // User name. User string // Host port (default: 22). Port string // Path to known_hosts file as per https://linux.die.net/man/8/sshd // "SSH_KNOWN_HOSTS FILE FORMAT" (default: "$HOME/.ssh/known_hosts"). The // known_hosts file must include the public key of the SFTP server for // authentication to succeed. KnownHostsFile string // Private key used for authentication. PrivateKey PrivateKey // RemoteDir is the directory path, relative to the SFTP root directory, // where PIPs should be uploaded. RemoteDir string }
Config represents the configuration needed to connect to an SFTP server.
func (*Config) SetDefaults ¶
func (c *Config) SetDefaults()
SetDefaults sets default values for some configs.
type GoClient ¶
type GoClient struct {
// contains filtered or unexported fields
}
GoClient implements the SFTP service using native Go SSH and SFTP packages.
func NewGoClient ¶
NewGoClient returns a new GoSFTP client with the given configuration.
func (*GoClient) Delete ¶
Delete removes the file or directory from dest. A new SFTP connection is opened before removing it, and closed when the delete is complete.
func (*GoClient) UploadDirectory ¶ added in v0.10.0
func (c *GoClient) UploadDirectory(ctx context.Context, srcPath string) (string, AsyncUpload, error)
UploadDirectory asynchronously copies a directory to dest over an SFTP connection.
When UploadDirectory is called it starts the upload in an asynchronous goroutine, then immediately returns the full remote path, and an AsyncUpload struct that provides access to the upload status and progress.
When the upload completes, the `AsyncUpload.Done()` channel is sent a `true` value. If an error occurs during the upload the error is sent to the `AsyncUpload.Error()` channel and the upload is terminated. If a ctx cancellation signal is received, the `ctx.Err()` error will be sent to the `AsyncUpload.Error()` channel, and the upload is terminated.
func (*GoClient) UploadFile ¶ added in v0.10.0
func (c *GoClient) UploadFile(ctx context.Context, src io.Reader, dest string) (string, AsyncUpload, error)
UploadFile asynchronously copies the src data to dest over an SFTP connection.
When UploadFile is called it starts the upload in an asynchronous goroutine, then immediately returns the full remote path, and an AsyncUpload struct that provides access to the upload status and progress.
When the upload completes, the `AsyncUpload.Done()` channel is sent a `true` value. If an error occurs during the upload the error is sent to the `AsyncUpload.Error()` channel and the upload is terminated. If a ctx cancellation signal is received, the `ctx.Err()` error will be sent to the `AsyncUpload.Error()` channel, and the upload is terminated.
type PrivateKey ¶
type PrivateKey struct { // Path to private key file used for authentication (default: // "$HOME/.ssh/id_rsa") Path string // Passphrase (if any) used to decrypt the private key. Passphrase string }
PrivateKey represents a SSH private key, with an optional passphrase.