()
| 39 | } |
| 40 | |
| 41 | func (l *SFTPLazy) Client() (SFTPClient, error) { |
| 42 | // Establish the SFTP connection only once on the first call, and reuse the connection in all subsequent calls |
| 43 | l.once.Do(func() { |
| 44 | client, err := connect(l.address, l.config) |
| 45 | if err != nil { |
| 46 | l.connErr = fmt.Errorf("lazy SSH connection error: %w", err) |
| 47 | } |
| 48 | l.client = client |
| 49 | }) |
| 50 | return l.client, l.connErr |
| 51 | } |
| 52 | |
| 53 | func connect(addr string, config *ssh.ClientConfig) (*sftp.Client, error) { |
| 54 | sshClient, err := ssh.Dial("tcp", addr, config) |
no test coverage detected