transport

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package transport holds the unexported FTP/FTPS/SFTP protocol implementations. It has no dependency on the root ramify package - callers adapt Endpoint/uploader to/from the options and clients here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FTPClient

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

FTPClient wraps a connected FTP (or FTPS, via explicit AUTH TLS) session. Not safe for concurrent use, matching the "one reused connection per endpoint worker" model the engine drives it with.

func DialFTP

func DialFTP(ctx context.Context, opts FTPDialOptions) (*FTPClient, error)

DialFTP connects and authenticates over plain FTP.

func DialFTPS

func DialFTPS(ctx context.Context, opts FTPSDialOptions) (*FTPClient, error)

DialFTPS connects and authenticates over FTP with explicit AUTH TLS. It returns the same FTPClient as DialFTP - once connected, FTP and FTPS sessions behave identically for upload/delete/verify/list.

func (*FTPClient) Close

func (c *FTPClient) Close() error

Close ends the session with a QUIT.

func (*FTPClient) Delete

func (c *FTPClient) Delete(remoteName string) error

Delete removes remoteName, treating "file doesn't exist" as success since it's called unconditionally before every upload under the delete-first overwrite mode.

func (*FTPClient) Size

func (c *FTPClient) Size(remoteName string) (int64, error)

Size returns the remote file's size in bytes via SIZE.

func (*FTPClient) Upload

func (c *FTPClient) Upload(
	remoteName string, r io.Reader, size int64, progress func(sent, total int64),
) error

Upload streams r (size bytes total) to remoteName via STOR, reporting cumulative bytes through progress.

func (*FTPClient) Verify

func (c *FTPClient) Verify(localPath, remoteName string) (method string, err error)

Verify checks localPath's size against the remote file's. jlaffaye/ftp exposes no FEAT/XCRC/XMD5/XSHA1 access, so FTP/FTPS verification is size-only.

type FTPDialOptions

type FTPDialOptions struct {
	Host           string
	Port           int // 0 means defaultFTPPort
	Username       string
	Password       string
	ConnectTimeout time.Duration
	StallTimeout   time.Duration // 0 disables idle-stall protection
}

FTPDialOptions configures a plain-FTP connection.

type FTPSDialOptions

type FTPSDialOptions struct {
	Host           string
	Port           int // 0 means defaultFTPPort
	Username       string
	Password       string
	ConnectTimeout time.Duration
	StallTimeout   time.Duration // 0 disables idle-stall protection
	// TLSConfig overrides the default. Optional; ServerName or
	// ClientSessionCache left unset are filled in automatically (see
	// resolveTLSConfig) - required for many servers' data connections.
	TLSConfig *tls.Config
}

FTPSDialOptions configures an explicit-AUTH-TLS FTP connection (the ftps protocol): the control connection starts on port 21 like plain FTP and upgrades via AUTH TLS, not implicit FTPS on a separate port.

type SFTPClient

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

SFTPClient wraps a connected SSH+SFTP session. Not safe for concurrent use.

func DialSFTP

func DialSFTP(ctx context.Context, opts SFTPDialOptions) (*SFTPClient, error)

DialSFTP connects over SSH and opens an SFTP session. The remote host key is verified against ~/.ssh/known_hosts - no insecure fallback; an unrecognized host fails, matching OpenSSH's trust-on-first-use flow.

func (*SFTPClient) Close

func (c *SFTPClient) Close() error

Close ends the SFTP session and the underlying SSH connection.

func (*SFTPClient) Delete

func (c *SFTPClient) Delete(remoteName string) error

Delete removes remoteName, treating "file doesn't exist" as success since it's called unconditionally before every upload under the delete-first overwrite mode.

func (*SFTPClient) Size

func (c *SFTPClient) Size(remoteName string) (int64, error)

Size returns the remote file's size in bytes.

func (*SFTPClient) Upload

func (c *SFTPClient) Upload(
	remoteName string, r io.Reader, size int64, progress func(sent, total int64),
) error

Upload streams r (size bytes total) to remoteName, reporting cumulative bytes through progress.

func (*SFTPClient) Verify

func (c *SFTPClient) Verify(localPath, remoteName string) (method string, err error)

Verify checks localPath's size against the remote file's. SFTP has no standard remote-hash command, so verification is size-only, like FTP/FTPS.

type SFTPDialOptions

type SFTPDialOptions struct {
	Host           string
	Port           int // 0 means defaultSFTPPort
	Username       string
	Password       string
	PrivateKeyPath string
	ConnectTimeout time.Duration
	StallTimeout   time.Duration // 0 disables idle-stall protection
}

SFTPDialOptions configures an SSH/SFTP connection. If both Password and PrivateKeyPath are set, the key takes priority and Password is tried as its passphrase; otherwise whichever is set is used alone.

Jump to

Keyboard shortcuts

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