sftp

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package sftp provides high-performance SFTP file and directory transfer capabilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BridgeKeyContentToWindows added in v0.4.0

func BridgeKeyContentToWindows(baseName string, content []byte) (string, error)

BridgeKeyContentToWindows mirrors raw private key bytes into the Windows-side OpsPulse key directory so that GUI clients running outside WSL can read them. It returns the native Windows path of the mirrored file.

Unlike an ephemeral temp file, this mirror is intentionally kept on disk: GUI clients open asynchronously and may read the key long after the launching process exits.

func BridgeKeyToWindows added in v0.4.0

func BridgeKeyToWindows(linuxKeyPath string) (string, error)

BridgeKeyToWindows copies the WSL SSH private key to the mirrored Windows directory. It returns the native Windows path (C:\...) to be passed to GUI clients.

func BuildLaunchCommand added in v0.4.0

func BuildLaunchCommand(client ClientInfo, srv server.Server, jumpSrv *server.Server, remotePath string) (*exec.Cmd, error)

BuildLaunchCommand prepares the *exec.Cmd to launch the specified SFTP client.

jumpSrv is the inventory entry srv.JumpHost resolves to, and is required whenever srv.JumpHost is set. Only the terminal OpenSSH client can be routed through it; every other client type is refused rather than launched against an address it cannot reach.

func IsWSL added in v0.4.0

func IsWSL() bool

IsWSL returns true if the current environment is running inside Windows Subsystem for Linux.

func LaunchAsync added in v0.4.0

func LaunchAsync(cmd *exec.Cmd) error

LaunchAsync executes a GUI client command in a detached, non-blocking process.

func Materialized1PKeyDir added in v0.4.0

func Materialized1PKeyDir() (string, error)

Materialized1PKeyDir returns the directory where temporary private keys are stored for GUI SFTP clients (~/.ssh/opspulse-1p).

Legacy: keys are no longer materialised there. The directory is only inspected and purged to clean up residue left by versions that resolved op:// references at connect time. Slated for removal in the next major version.

func PurgeMaterialized1PKeys added in v0.4.0

func PurgeMaterialized1PKeys(serverName string) ([]string, error)

PurgeMaterialized1PKeys deletes temporary private keys from ~/.ssh/opspulse-1p. If serverName is non-empty, only that server's key is removed. If serverName is empty, all keys in the directory are removed. Returns the list of deleted server key names and any encountered error.

Legacy: it exists to clean up residue from the op:// era. `ops 1p restore` calls it once after migrating; the `ops sftp --cleanup` flag that used to expose it to users has since been removed.

func WindowsUserHome added in v0.4.0

func WindowsUserHome() (string, error)

WindowsUserHome returns the WSL path to the Windows user's home directory (e.g., /mnt/c/Users/username).

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client encapsulates an active SFTP session backed by an SSH connection.

func NewClient

func NewClient(srv server.Server, timeout time.Duration) (*Client, error)

NewClient establishes an SSH connection and initializes an SFTP subsystem client.

func NewClientWithJumpAndWriter added in v0.4.0

func NewClientWithJumpAndWriter(srv server.Server, jump *server.Server, timeout time.Duration, warnWriter io.Writer) (*Client, error)

NewClientWithJumpAndWriter establishes an SSH connection (optionally through a jump host and with a custom warning writer) and initializes an SFTP subsystem client.

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying SFTP and SSH connections.

func (*Client) DownloadDir

func (c *Client) DownloadDir(remoteDir, localDir string) (int, int64, error)

DownloadDir recursively downloads a remote directory to a local directory.

func (*Client) DownloadFile

func (c *Client) DownloadFile(remotePath, localPath string) (int64, error)

DownloadFile downloads a single remote file to the destination local path.

func (*Client) UploadDir

func (c *Client) UploadDir(localDir, remoteDir string) (int, int64, error)

UploadDir recursively uploads a local directory to a remote directory.

func (*Client) UploadFile

func (c *Client) UploadFile(localPath, remotePath string) (int64, error)

UploadFile uploads a single local file to the destination remote path.

type ClientInfo added in v0.4.0

type ClientInfo struct {
	Type        ClientType
	Name        string
	Path        string
	IsGUI       bool
	Description string
}

ClientInfo describes a detected or configured SFTP client.

func DetectAvailableClients added in v0.4.0

func DetectAvailableClients() []ClientInfo

DetectAvailableClients discovers all installed GUI and CLI SFTP clients on the host system.

func FindClient added in v0.4.0

func FindClient(preference string, preferCLI bool) (*ClientInfo, error)

FindClient resolves a preferred client name or discovers the best available client.

type ClientType added in v0.4.0

type ClientType string

ClientType denotes the category of SFTP client.

const (
	// ClientWinSCP represents the WinSCP client on Windows.
	ClientWinSCP ClientType = "winscp"
	// ClientXftp represents NetSarang Xftp on Windows.
	ClientXftp ClientType = "xftp"
	// ClientFileZilla represents the FileZilla FTP/SFTP client.
	ClientFileZilla ClientType = "filezilla"
	// ClientCyberduck represents Cyberduck on macOS.
	ClientCyberduck ClientType = "cyberduck"
	// ClientTransmit represents Panic Transmit on macOS.
	ClientTransmit ClientType = "transmit"
	// ClientSystem represents the operating system's default protocol handler.
	ClientSystem ClientType = "system"
	// ClientOpenSSH represents the standard terminal OpenSSH sftp command.
	ClientOpenSSH ClientType = "openssh"
)

type MaterializedKeyInfo added in v0.4.0

type MaterializedKeyInfo struct {
	Name    string
	ModTime time.Time
	IsStale bool // True if older than 24 hours
}

MaterializedKeyInfo describes a temporary private key file in ~/.ssh/opspulse-1p.

func ListMaterialized1PKeyDetails added in v0.4.0

func ListMaterialized1PKeyDetails() ([]MaterializedKeyInfo, error)

ListMaterialized1PKeyDetails returns detailed metadata for all materialized keys in ~/.ssh/opspulse-1p.

Legacy: see Materialized1PKeyDir.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址