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 ¶
- type AcceptFunc
- type FileInfo
- type SCP
- func (s *SCP) Receive(srcFile string, dest io.Writer) (os.FileInfo, error)
- func (s *SCP) ReceiveDir(srcDir, destDir string, acceptFn AcceptFunc) error
- func (s *SCP) ReceiveFile(srcFile, destFile string) error
- func (s *SCP) Send(info *FileInfo, r io.ReadCloser, destFile string) error
- func (s *SCP) SendDir(srcDir, destDir string, acceptFn AcceptFunc) error
- func (s *SCP) SendFile(srcFile, destFile string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AcceptFunc ¶
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 ¶
AccessTime returns access time.
type SCP ¶
type SCP struct {
// contains filtered or unexported fields
}
SCP is the type for the SCP client.
func (*SCP) Receive ¶
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 ¶
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 ¶
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.