Documentation
¶
Index ¶
- type ProgressFunc
- type RemoteEntry
- type SFTPClient
- func (c *SFTPClient) Close() error
- func (c *SFTPClient) Download(remotePath, localPath string) error
- func (c *SFTPClient) DownloadPath(ctx context.Context, remotePath, localPath string, progress ProgressFunc) error
- func (c *SFTPClient) DownloadWithProgress(remotePath, localPath string, progress func(downloaded, total int64)) error
- func (c *SFTPClient) DownloadWithProgressCtx(ctx context.Context, remotePath, localPath string, ...) error
- func (c *SFTPClient) HostName() string
- func (c *SFTPClient) ListDir(path string) ([]RemoteEntry, error)
- func (c *SFTPClient) Mkdir(path string) error
- func (c *SFTPClient) MkdirAll(remotePath string) error
- func (c *SFTPClient) RealPath(path string) (string, error)
- func (c *SFTPClient) Remove(path string) error
- func (c *SFTPClient) RemoveAll(path string) error
- func (c *SFTPClient) Rename(oldPath, newPath string) error
- func (c *SFTPClient) Stat(path string) (os.FileInfo, error)
- func (c *SFTPClient) Upload(localPath, remotePath string) error
- func (c *SFTPClient) UploadPath(ctx context.Context, localPath, remotePath string, progress ProgressFunc) error
- func (c *SFTPClient) UploadWithProgress(localPath, remotePath string, progress func(uploaded, total int64)) error
- func (c *SFTPClient) UploadWithProgressCtx(ctx context.Context, localPath, remotePath string, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ProgressFunc ¶ added in v0.6.2
type ProgressFunc func(transferred, total int64)
ProgressFunc reports transfer progress for a single file.
type RemoteEntry ¶
type RemoteEntry struct {
Name string
LongName string
IsDir bool
Size int64
ModTime time.Time
Mode string
}
RemoteEntry represents a file/dir entry on the remote host.
type SFTPClient ¶
type SFTPClient struct {
// contains filtered or unexported fields
}
SFTPClient wraps an SSH connection + one reused SFTP session. All remote ops share that session and are serialized with mu so a directory refresh cannot overlap an in-flight upload/download.
func Connect ¶
func Connect(hostName string, configFile string) (*SFTPClient, error)
Connect establishes an SSH connection to the given host and returns an SFTPClient. It resolves effective SSH settings (ssh -G when available) so IdentityFile entries from Host * / merged config work the same as interactive ssh.
func ConnectWithPassword ¶
func ConnectWithPassword(hostName string, configFile string, password string) (*SFTPClient, error)
ConnectWithPassword connects to the host using publickey + password auth. password can be empty to try publickey only, or a password to try keyboard-interactive + password auth as fallback.
func (*SFTPClient) Close ¶
func (c *SFTPClient) Close() error
Close closes the SFTP session and the underlying SSH connection.
func (*SFTPClient) Download ¶
func (c *SFTPClient) Download(remotePath, localPath string) error
Download downloads a remote file to a local path.
func (*SFTPClient) DownloadPath ¶ added in v0.6.2
func (c *SFTPClient) DownloadPath(ctx context.Context, remotePath, localPath string, progress ProgressFunc) error
DownloadPath downloads a remote file or directory to the local path. Directories are transferred recursively.
func (*SFTPClient) DownloadWithProgress ¶
func (c *SFTPClient) DownloadWithProgress(remotePath, localPath string, progress func(downloaded, total int64)) error
DownloadWithProgress downloads a remote file with a progress callback. The callback receives bytes downloaded and total size.
func (*SFTPClient) DownloadWithProgressCtx ¶ added in v0.6.1
func (c *SFTPClient) DownloadWithProgressCtx(ctx context.Context, remotePath, localPath string, progress func(downloaded, total int64)) error
DownloadWithProgressCtx is like DownloadWithProgress but accepts a context for cancellation.
func (*SFTPClient) HostName ¶
func (c *SFTPClient) HostName() string
HostName returns the name of the connected host.
func (*SFTPClient) ListDir ¶
func (c *SFTPClient) ListDir(path string) ([]RemoteEntry, error)
ListDir lists the contents of a remote directory.
func (*SFTPClient) Mkdir ¶
func (c *SFTPClient) Mkdir(path string) error
Mkdir creates a directory on the remote host.
func (*SFTPClient) MkdirAll ¶ added in v0.6.2
func (c *SFTPClient) MkdirAll(remotePath string) error
MkdirAll creates a remote directory and any missing parents.
func (*SFTPClient) RealPath ¶
func (c *SFTPClient) RealPath(path string) (string, error)
RealPath returns the canonical absolute path.
func (*SFTPClient) Remove ¶
func (c *SFTPClient) Remove(path string) error
Remove deletes a file on the remote host.
func (*SFTPClient) RemoveAll ¶ added in v0.7.3
func (c *SFTPClient) RemoveAll(path string) error
RemoveAll deletes a remote file or directory recursively.
func (*SFTPClient) Rename ¶ added in v0.7.3
func (c *SFTPClient) Rename(oldPath, newPath string) error
Rename moves a remote file or directory to a new path.
func (*SFTPClient) Stat ¶
func (c *SFTPClient) Stat(path string) (os.FileInfo, error)
Stat returns info about a remote path.
func (*SFTPClient) Upload ¶
func (c *SFTPClient) Upload(localPath, remotePath string) error
Upload uploads a local file to a remote path.
func (*SFTPClient) UploadPath ¶ added in v0.6.2
func (c *SFTPClient) UploadPath(ctx context.Context, localPath, remotePath string, progress ProgressFunc) error
UploadPath uploads a local file or directory to the remote path. Directories are transferred recursively.
func (*SFTPClient) UploadWithProgress ¶
func (c *SFTPClient) UploadWithProgress(localPath, remotePath string, progress func(uploaded, total int64)) error
UploadWithProgress uploads a local file with a progress callback.
func (*SFTPClient) UploadWithProgressCtx ¶ added in v0.6.1
func (c *SFTPClient) UploadWithProgressCtx(ctx context.Context, localPath, remotePath string, progress func(uploaded, total int64)) error
UploadWithProgressCtx is like UploadWithProgress but accepts a context for cancellation.