transfer

package
v1.0.32 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package transfer provides file transfer functionality using SCP/SFTP

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandPath

func ExpandPath(path string) (string, error)

ExpandPath expands ~ to home directory and makes path absolute

func GetSSHFSInstallInstructions

func GetSSHFSInstallInstructions() string

GetSSHFSInstallInstructions returns platform-specific install instructions

func IsPickerAvailable

func IsPickerAvailable() bool

IsPickerAvailable checks if native file picker is available on this system

func IsSSHFSAvailable

func IsSSHFSAvailable() bool

IsSSHFSAvailable checks if SSHFS is installed

func ValidateLocalPath

func ValidateLocalPath(path string, direction Direction) error

ValidateLocalPath checks if a local path is valid for the given direction

Types

type Direction

type Direction int

Direction represents the transfer direction

const (
	Upload Direction = iota
	Download
)

func (Direction) String

func (d Direction) String() string

type FileInfo

type FileInfo struct {
	Name  string
	IsDir bool
	Size  int64
}

FileInfo represents basic file information

func GetLocalFiles

func GetLocalFiles(path string) ([]FileInfo, error)

GetLocalFiles returns a list of files/directories in the given path

type PickerMode

type PickerMode int

PickerMode defines whether we're selecting files or directories

const (
	PickFile PickerMode = iota
	PickDirectory
	PickMultiple // Multiple files
)

type PickerResult

type PickerResult struct {
	Selected  bool     // True if user selected something (didn't cancel)
	Path      string   // Single path (for PickFile/PickDirectory)
	Paths     []string // Multiple paths (for PickMultiple)
	Directory string   // The directory where selection was made
}

PickerResult contains the result of a file picker operation

func OpenFilePicker

func OpenFilePicker(mode PickerMode, title string, startDir string) (*PickerResult, error)

OpenFilePicker opens the native OS file picker dialog

func OpenRemoteDirectoryPicker

func OpenRemoteDirectoryPicker(host, startPath, configFile string) (*PickerResult, error)

OpenRemoteDirectoryPicker opens picker for selecting remote directory

func OpenRemoteFilePicker

func OpenRemoteFilePicker(host, startPath, configFile string, mode PickerMode, title string) (*PickerResult, error)

OpenRemoteFilePicker mounts remote filesystem and opens native file picker

func OpenRemoteFolderInFinder

func OpenRemoteFolderInFinder(host, startPath, configFile string) (*PickerResult, error)

OpenRemoteFolderInFinder mounts and opens Finder, returns selected path when done

func OpenSavePicker

func OpenSavePicker(title string, defaultName string, startDir string) (*PickerResult, error)

OpenSavePicker opens a native save dialog to select destination

type RemoteFile

type RemoteFile struct {
	Name    string
	Path    string
	IsDir   bool
	Size    int64
	ModTime string
}

RemoteFile represents a file on the remote server

type RunningTransfer

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

RunningTransfer represents a transfer that can be cancelled

func (*RunningTransfer) Cancel

func (rt *RunningTransfer) Cancel()

Cancel kills the running transfer

func (*RunningTransfer) Done

func (rt *RunningTransfer) Done() <-chan *TransferResult

Done returns a channel that receives the result when transfer completes

type SFTPSession

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

SFTPSession manages an SFTP connection for browsing

func NewSFTPSession

func NewSFTPSession(host, configFile string) (*SFTPSession, error)

NewSFTPSession creates a new SFTP session using SSH agent

func (*SFTPSession) Close

func (s *SFTPSession) Close() error

Close closes the SFTP session

func (*SFTPSession) GetHomeDirectory

func (s *SFTPSession) GetHomeDirectory() (string, error)

GetHomeDirectory returns the remote home directory

func (*SFTPSession) HasLocate

func (s *SFTPSession) HasLocate() bool

HasLocate checks if locate/mlocate is available on the remote system

func (*SFTPSession) ListDirectory

func (s *SFTPSession) ListDirectory(path string) ([]RemoteFile, error)

ListDirectory lists files in a remote directory

func (*SFTPSession) QuickSearch

func (s *SFTPSession) QuickSearch(pattern, startDir string, limit int) ([]RemoteFile, error)

QuickSearch does a faster search without fetching file details Uses timeout and depth limit to avoid slow searches

func (*SFTPSession) ReadFile

func (s *SFTPSession) ReadFile(path string, w io.Writer) error

ReadFile reads a remote file (for small files only)

func (*SFTPSession) Search

func (s *SFTPSession) Search(pattern, startDir string, limit int) ([]RemoteFile, error)

Search searches for files matching the pattern Uses locate if available (fast, indexed), otherwise falls back to find

func (*SFTPSession) Stat

func (s *SFTPSession) Stat(path string) (*RemoteFile, error)

Stat returns file info for a remote path

type SSHFSMount

type SSHFSMount struct {
	Host       string
	RemotePath string
	MountPoint string
	ConfigFile string
}

SSHFSMount represents a mounted SSHFS filesystem

func NewSSHFSMount

func NewSSHFSMount(host, remotePath, configFile string) (*SSHFSMount, error)

NewSSHFSMount creates a new SSHFS mount

func (*SSHFSMount) Mount

func (m *SSHFSMount) Mount() error

Mount mounts the remote filesystem

func (*SSHFSMount) ToRemotePath

func (m *SSHFSMount) ToRemotePath(localPath string) (string, error)

ToRemotePath converts a local path within the mount to a remote path

func (*SSHFSMount) Unmount

func (m *SSHFSMount) Unmount() error

Unmount unmounts the remote filesystem

type TransferRequest

type TransferRequest struct {
	Host       string    // SSH host name from config
	Direction  Direction // Upload or Download
	LocalPath  string    // Local file/directory path
	RemotePath string    // Remote file/directory path
	Recursive  bool      // Transfer directories recursively
	ConfigFile string    // Optional SSH config file path
}

TransferRequest represents a file transfer request

func ParseTransferArgs

func ParseTransferArgs(source, dest string) (*TransferRequest, error)

ParseTransferArgs parses scp-style arguments into a TransferRequest Examples:

  • "./local.txt", "host:/remote/path" -> Upload
  • "host:/remote/file.txt", "./local/" -> Download

func (*TransferRequest) BuildSCPCommand

func (r *TransferRequest) BuildSCPCommand() *exec.Cmd

BuildSCPCommand builds the scp command for the transfer

func (*TransferRequest) Execute

func (r *TransferRequest) Execute() *TransferResult

Execute runs the transfer and returns the result

func (*TransferRequest) ExecuteWithProgress

func (r *TransferRequest) ExecuteWithProgress() *TransferResult

ExecuteWithProgress runs the transfer with progress callback This uses scp's built-in progress indicator

func (*TransferRequest) StartTransfer

func (r *TransferRequest) StartTransfer() *RunningTransfer

StartTransfer starts a transfer and returns a RunningTransfer that can be cancelled

type TransferResult

type TransferResult struct {
	Success   bool
	BytesSent int64
	Error     error
}

TransferResult represents the result of a transfer operation

Jump to

Keyboard shortcuts

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