sftp

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCommand

func BuildCommand(h HostConnection) (name string, args []string)

BuildCommand returns the sftp command and args for the given connection. Caller can run it (e.g. in a new terminal) or display it.

func DownloadRecursive

func DownloadRecursive(ctx context.Context, client *sftp.Client, remotePath, localPath string, workers int, progress func(TransferProgress)) error

func ListRemote

func ListRemote(conn *ssh.Client, path string) ([]os.FileInfo, error)

ListRemote lists the given path on the remote server over the SSH connection. Caller must ensure conn is valid; it is not closed by this function.

func RunInNewTerminal

func RunInNewTerminal(h HostConnection) (cmdStr string, err error)

RunInNewTerminal runs the sftp command in a new terminal window so the user can interact with it. On macOS uses Terminal.app via osascript; on Linux tries gnome-terminal or xterm; on Windows uses cmd start. Returns the command string and any error (e.g. if no terminal could be launched).

func RunSCP

func RunSCP(h HostConnection, direction string, localPath, remotePath string) (output string, err error)

RunSCP runs scp for push (local → remote) or pull (remote → local). Returns combined output.

func RunSCPHostToHost

func RunSCPHostToHost(source HostConnection, sourcePath string, dest HostConnection, destPath string) (output string, err error)

RunSCPHostToHost copies from source host to dest host (stream goes through local machine). Both source and dest are remote paths: user@host:path.

func UploadRecursive

func UploadRecursive(ctx context.Context, client *sftp.Client, localPath, remotePath string, workers int, progress func(TransferProgress)) error

Types

type HostConnection

type HostConnection struct {
	User         string
	Hostname     string
	Port         int
	IdentityFile string
}

HostConnection holds the connection details for building an sftp command.

type TransferProgress

type TransferProgress struct {
	Path  string
	Bytes int64
	Total int64
	Done  bool
	Err   error
}

func (TransferProgress) String

func (p TransferProgress) String() string

Jump to

Keyboard shortcuts

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