Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support extended configuration fields to enable the extended features of ftpserverlib. #1454

Open
Ning-Qing opened this issue Jan 23, 2025 · 0 comments

Comments

@Ning-Qing
Copy link

Ning-Qing commented Jan 23, 2025

For example, enable the HASH feature.

// Extensions define the relevant configurations for extended features
type Extensions struct {
	EnableHASH bool `json:"enable_hash"` // Enable support for calculating hash value of files
}

// Content defines the content of the config file
type Content struct {
	Version                  int        `json:"version"`                     // File format version
	ListenAddress            string     `json:"listen_address"`              // Address to listen on
	PublicHost               string     `json:"public_host"`                 // Public host to listen on
	MaxClients               int        `json:"max_clients"`                 // Maximum clients who can connect
	HashPlaintextPasswords   bool       `json:"hash_plaintext_passwords"`    // Overwrite plain-text passwords with hashed equivalents
	Accesses                 []*Access  `json:"accesses"`                    // Accesses offered to users
	PassiveTransferPortRange *PortRange `json:"passive_transfer_port_range"` // Listen port range
	Extensions               Extensions `json:"extensions"`                  // Extended features
	Logging                  Logging    `json:"logging"`                     // Logging parameters
	TLS                      *TLS       `json:"tls"`
}
// GetSettings returns some general settings around the server setup
func (s *Server) GetSettings() (*serverlib.Settings, error) {
	conf := s.config.Content

	var portRange *serverlib.PortRange

	if conf.PassiveTransferPortRange != nil {
		portRange = &serverlib.PortRange{
			Start: conf.PassiveTransferPortRange.Start,
			End:   conf.PassiveTransferPortRange.End,
		}
	}

	return &serverlib.Settings{
		ListenAddr:               conf.ListenAddress,
		PublicHost:               conf.PublicHost,
		PassiveTransferPortRange: portRange,
		EnableHASH:               conf.Extensions.EnableHASH,
	}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant