diff --git a/client.go b/client.go index 307a35ea..895bad6b 100644 --- a/client.go +++ b/client.go @@ -16,7 +16,6 @@ import ( "time" "github.com/kr/fs" - "golang.org/x/crypto/ssh" "github.com/pkg/sftp/internal/encoding/ssh/filexfer/openssh" ) @@ -192,34 +191,6 @@ type Client struct { disableConcurrentReads bool } -// NewClient creates a new SFTP client on conn, using zero or more option -// functions. -func NewClient(conn *ssh.Client, opts ...ClientOption) (*Client, error) { - s, err := conn.NewSession() - if err != nil { - return nil, err - } - - pw, err := s.StdinPipe() - if err != nil { - return nil, err - } - pr, err := s.StdoutPipe() - if err != nil { - return nil, err - } - perr, err := s.StderrPipe() - if err != nil { - return nil, err - } - - if err := s.RequestSubsystem("sftp"); err != nil { - return nil, err - } - - return newClientPipe(pr, perr, pw, s.Wait, opts...) -} - // NewClientPipe creates a new SFTP client given a Reader and a WriteCloser. // This can be used for connecting to an SFTP server over TCP/TLS or by using // the system's ssh client program (e.g. via exec.Command). diff --git a/client_ssh.go b/client_ssh.go new file mode 100644 index 00000000..c49a8d84 --- /dev/null +++ b/client_ssh.go @@ -0,0 +1,33 @@ +//go:build !pkg_sftp.omit_ssh + +package sftp + +import "golang.org/x/crypto/ssh" + +// NewClient creates a new SFTP client on conn, using zero or more option +// functions. +func NewClient(conn *ssh.Client, opts ...ClientOption) (*Client, error) { + s, err := conn.NewSession() + if err != nil { + return nil, err + } + + pw, err := s.StdinPipe() + if err != nil { + return nil, err + } + pr, err := s.StdoutPipe() + if err != nil { + return nil, err + } + perr, err := s.StderrPipe() + if err != nil { + return nil, err + } + + if err := s.RequestSubsystem("sftp"); err != nil { + return nil, err + } + + return newClientPipe(pr, perr, pw, s.Wait, opts...) +}