scp

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 10 Imported by: 1

README

WAT

Offers and implementation for getting files or sending files via SCP in Go. This library is effectivly wrapped by https://github.com/EugenMayer/go-sshclient, you should use go-ssclient in your project since it provides an convenient interface for SCP and SSH

Example

See https://github.com/EugenMayer/go-sshclient/blob/master/scpwrapper/from_remote.go#L11

Credits

Forked on the great work of https://github.com/hnakamur/go-scp

License

MIT

Documentation

Overview

Package scp provides functions to copy a single file or to copy files and directories under a directory recursively between the localhost and a remote server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcceptFunc

type AcceptFunc func(parentDir string, info os.FileInfo) (bool, error)

AcceptFunc is the type of the function called for each file or directory to determine whether is should be copied or not. In SendDir, parentDir will be a directory under srcDir. In ReceiveDir, parentDir will be a directory under destDir.

type FileInfo

type FileInfo struct {
	// contains filtered or unexported fields
}

FileInfo represents a file or a directory information.

func NewFileInfo

func NewFileInfo(name string, size int64, mode os.FileMode, modTime, accessTime time.Time) *FileInfo

NewFileInfo creates a file information. The filepath.Base(name) is used as the name and the mode is masked with (os.ModePerm | os.ModeDir).

func (*FileInfo) AccessTime

func (i *FileInfo) AccessTime() time.Time

AccessTime returns access time.

func (*FileInfo) IsDir

func (i *FileInfo) IsDir() bool

IsDir is abbreviation for Mode().IsDir().

func (*FileInfo) ModTime

func (i *FileInfo) ModTime() time.Time

ModTime returns modification time.

func (*FileInfo) Mode

func (i *FileInfo) Mode() os.FileMode

Mode returns file mode bits.

func (*FileInfo) Name

func (i *FileInfo) Name() string

Name returns base name of the file.

func (*FileInfo) Size

func (i *FileInfo) Size() int64

Size length in bytes for regular files; system-dependent for others.

func (*FileInfo) Sys

func (i *FileInfo) Sys() interface{}

Sys returns underlying data source (can return nil).

type SCP

type SCP struct {
	// contains filtered or unexported fields
}

SCP is the type for the SCP client.

func NewSCP

func NewSCP(client *ssh.Client) *SCP

NewSCP creates the SCP client.

func (*SCP) Receive

func (s *SCP) Receive(srcFile string, dest io.Writer) (os.FileInfo, error)

Receive copies a single remote file to the specified writer and returns the file information. The actual type of the file information is scp.FileInfo, and you can get the access time with fileInfo.(*scp.FileInfo).AccessTime().

func (*SCP) ReceiveDir

func (s *SCP) ReceiveDir(srcDir, destDir string, acceptFn AcceptFunc) error

ReceiveDir copies files and directories under a remote srcDir to to the destDir on the local machine. You can filter the files and directories to be copied with acceptFn. If acceptFn is nil, all files and directories will be copied. The time and permission will be set to the same value of the source file or directory.

func (*SCP) ReceiveFile

func (s *SCP) ReceiveFile(srcFile, destFile string) error

ReceiveFile copies a single remote file to the local machine with the specified name. The time and permission will be set to the same value of the source file.

func (*SCP) Send

func (s *SCP) Send(info *FileInfo, r io.ReadCloser, destFile string) error

Send reads a single local file content from the r, and copies it to the remote file with the name destFile. The time and permission will be set with the value of info. The r will be closed after copying. If you don't want for r to be closed, you can pass the result of ioutil.NopCloser(r).

func (*SCP) SendDir

func (s *SCP) SendDir(srcDir, destDir string, acceptFn AcceptFunc) error

SendDir copies files and directories under the local srcDir to to the remote destDir. You can filter the files and directories to be copied with acceptFn. However this filtering is done at the receiver side, so all file bodies are transferred over the network even if some files are filtered out. If you need more efficiency, it is better to use another method like the tar command. If acceptFn is nil, all files and directories will be copied. The time and permission will be set to the same value of the source file or directory.

func (*SCP) SendFile

func (s *SCP) SendFile(srcFile, destFile string) error

SendFile copies a single local file to the remote server. The time and permission will be set with the value of the source file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL