gofr-dev/gofr · error

invalid FTP configuration: host and port are required

Error message

invalid FTP configuration: host and port are required

What it means

errInvalidConfig is returned by the FTP filesystem's validateConfig when the Config lacks a host or port, which are mandatory to reach an FTP server. It signals the FTP filesystem cannot be used until host and port are supplied in the Config struct.

Source

Thrown at pkg/gofr/datasource/file/ftp/fs.go:13

package ftp

import (
	"context"
	"errors"
	"fmt"
	"time"

	"gofr.dev/pkg/gofr/datasource/file"
)

var (
	errInvalidConfig   = errors.New("invalid FTP configuration: host and port are required")
	errInvalidProvider = errors.New("invalid FTP provider")
)

const defaultTimeout = 10 * time.Second

type fileSystem struct {
	*file.CommonFileSystem
}

// New creates and validates a new FTP file system.
// Returns error if connection fails or configuration is invalid.
func New(config *Config) file.FileSystemProvider {
	if config == nil {
		config = &Config{}
	}

	// Set default dial timeout if not specified
	if config.DialTimeout == 0 {

View on GitHub (pinned to 187eb24962)

Solutions

  1. Set Config.Host and Config.Port (port defaults to 21 only for display; validation still requires them) before calling Connect().
  2. Load host/port from environment or config file and fail fast at startup if empty.
  3. Check the error via errors.Is(err, ftp.ErrInvalidConfig) and skip/skip-connect rather than retrying.

Example fix

// before
fs := ftp.New(&ftp.Config{RemoteDir: "/data"})
fs.Connect()
// after
fs := ftp.New(&ftp.Config{Host: "ftp.example.com", Port: 21, RemoteDir: "/data"})
fs.Connect()
Defensive patterns

Strategy: validation

Validate before calling

func validFTPConfig(c *ftp.Config) bool {
    if c == nil { return false }
    return c.Host != "" && c.Port != 0
}

Try / catch

fs := ftp.New(cfg)
if err := fs.ValidateConfig(); err != nil { // or errors.Is on Connect logs
    log.Fatalf("ftp config invalid: %v", err)
}

Prevention

When it happens

Trigger: Calling Connect() (or validateConfig) on ftp.New(&ftp.Config{}) with an empty Host, or a Config where both host and port are unset.

Common situations: Forgetting to populate host/port from environment variables; constructing Config{} with only a remote dir; nil Config defaulting to an empty struct; config struct fields renamed in a version upgrade.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/b107a4ca960df602. Report an issue: GitHub.