Provide a function which allows to open files from the remote server and read from them via an io.Reader.
Description
The proposed function ReceiveOpen returns a FileInfo to the caller similar to Receive. The difference to Receive is, that writing to an io.Writer provided by the caller, the caller gets an io.Reader.
The main advantage is that it provides the consumer more control over reading process. This would allow better integration of go-scp with other golang modules. For example, the io.Reader can be wrapped in high level Reader implementations provided by the io package.
Proposed changes
Add the function ReceiveOpen:
// ReceiveOpen returns a FileInfo and a ReadCloser
func (*SCP) ReceiveOpen(srcFile string) (*FileInfo, io.ReadCloser, error)
Example usage
// Open file on remote server
reader, fileInfo, err := scp.NewSCP(c).ReceiveOpen(remotePath)
defer reader.Close()
if err != nil {
panic(err)
}
// Read file data into slice
data, err := ioutil.ReadAll(reader)
if err != nil {
panic(err)
}
Provide a function which allows to open files from the remote server and read from them via an
io.Reader
.Description
The proposed function
ReceiveOpen
returns aFileInfo
to the caller similar toReceive
. The difference toReceive
is, that writing to anio.Writer
provided by the caller, the caller gets anio.Reader
.The main advantage is that it provides the consumer more control over reading process. This would allow better integration of
go-scp
with other golang modules. For example, theio.Reader
can be wrapped in high level Reader implementations provided by theio
package.Proposed changes
Add the function
ReceiveOpen
:Example usage