Skip to content

ReadFile or ScpGet #100

Description

@nicobistolfi

Have you consider adding a new method to copy a file from a remote ssh server to the client?

Could be implemented by adding a method to the MakeConfig struct, names could be ReadFile or ScpGet.

Proposed Method Signature:

func (ssh_conf *MakeConfig) ReadFile(remoteFile string) (io.Reader, error)
// OR
func (ssh_conf *MakeConfig) ScpGet(remoteFile string) (io.Reader, error) 

This method would establish an SSH session, execute the necessary remote command (like cat or internal SFTP/SCP logic), and return an io.Reader.

This pattern would allow handling the output efficiently using standard Go I/O utilities, like copying directly to a local file:

reader, err := ssh.ReadFile("/remote/path/file.dat")
if err != nil { /* ... */ }

// Copy the remote stream directly to a local file
localFile, err := os.Create("/local/path/file.dat")
if err != nil { /* ... */ }
defer localFile.Close()

_, err = io.Copy(localFile, reader)

Happy to do submit PR myself if this is something you'd like to add to the library.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions