Skip to content

Commit 1841078

Browse files
committed
feat(sshx): allow to disable SFTP subsystem
1 parent f80973a commit 1841078

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

pkg/sshx/client.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ func NewClient(config *Config, options ...Option) (*Client, error) {
7777
}
7878
}
7979

80-
if client.SFTP, err = sftp.NewClient(client.SSH); err != nil {
81-
return nil, err
80+
// Prevent issues with SSH servers that do not permit SFTP.
81+
if !client.STFPDisabled {
82+
if client.SFTP, err = sftp.NewClient(client.SSH); err != nil {
83+
return nil, err
84+
}
8285
}
8386

8487
return client, nil

pkg/sshx/options.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88

99
// Options contains the configuration for an operation.
1010
type Options struct {
11-
Logger *zerolog.Logger
12-
Proxy *Client
13-
Timeout time.Duration
11+
Logger *zerolog.Logger
12+
Proxy *Client
13+
Timeout time.Duration
14+
STFPDisabled bool
1415
}
1516

1617
// Option applies a configuration option
@@ -33,9 +34,10 @@ func GetDefaultOptions() *Options {
3334
logger := zerolog.Nop()
3435

3536
return &Options{
36-
Proxy: nil,
37-
Timeout: time.Second * 5,
38-
Logger: &logger,
37+
Proxy: nil,
38+
Timeout: time.Second * 5,
39+
Logger: &logger,
40+
STFPDisabled: false,
3941
}
4042
}
4143

@@ -63,3 +65,11 @@ func WithTimeout(timeout time.Duration) Option {
6365
return nil
6466
}
6567
}
68+
69+
// WithSTFPDisabled allows to disable the SFTP client.
70+
func WithSTFPDisabled() Option {
71+
return func(options *Options) error {
72+
options.STFPDisabled = true
73+
return nil
74+
}
75+
}

0 commit comments

Comments
 (0)