Documentation
¶
Overview ¶
Package ftpclient is a minimal FTP client that supports both passive (EPSV/PASV) and active (PORT/EPRT) data connection modes, with explicit context propagation for connect and data transfer operations.
It exists because the third-party FTP clients we evaluated were passive-only, which fails against FTP servers whose advertised PASV port is firewalled.
Index ¶
- type Client
- func (c *Client) Cwd(path string) error
- func (c *Client) Delete(path string) error
- func (c *Client) List(ctx context.Context, path string) ([]Entry, error)
- func (c *Client) Login(user, pass string) error
- func (c *Client) Mkdir(path string) error
- func (c *Client) Pwd() (string, error)
- func (c *Client) Quit() error
- func (c *Client) Rename(from, to string) error
- func (c *Client) Retrieve(ctx context.Context, path string) (io.ReadCloser, error)
- func (c *Client) Rmdir(path string) error
- func (c *Client) Size(path string) (int64, error)
- func (c *Client) Store(ctx context.Context, path string, r io.Reader) error
- type DataMode
- type Entry
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an FTP client. It is not safe for concurrent use across operations.
func Dial ¶
Dial opens a control connection to addr and reads the welcome banner. Callers must subsequently call Login before invoking other commands.
func (*Client) List ¶
List enumerates a directory. It prefers MLSD when the server advertises it (machine-parseable, format-stable) and falls back to LIST. The LIST parser handles both Unix `ls -l` and Microsoft IIS DOS-style listings, since these are the two dialects we see in the wild.
func (*Client) Login ¶
Login authenticates with USER/PASS, then probes server features and switches to binary transfer mode (TYPE I). Binary mode is needed for both RETR and STOR to avoid byte mangling on text vs. binary content.
func (*Client) Retrieve ¶
Retrieve downloads a file. The returned reader must be fully consumed and closed by the caller; closing reads the 226 transfer-complete response.
type DataMode ¶
type DataMode string
DataMode controls how the data connection is established for LIST/RETR/STOR.
const ( // DataModeAuto tries passive first and falls back to active if the passive // data connection cannot be dialed. DataModeAuto DataMode = "auto" // DataModePassive uses EPSV/PASV only. DataModePassive DataMode = "passive" // DataModeActive uses EPRT/PORT only. DataModeActive DataMode = "active" )