scp

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

README

scp in Go

Install

go get -u github.com/ImSingee/scp

Usage

Go Reference

Simple Copy
package main
import "golang.org/x/crypto/ssh"
import "github.com/ImSingee/scp"

func main() {
    // make session
    client, _ := ssh.Dial("tcp", "remote-addr:22", &ssh.ClientConfig{
		User: "root",
		Auth: []ssh.AuthMethod{
			ssh.Password("root"),
		},
		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
		BannerCallback:  ssh.BannerDisplayStderr(),
	})
    defer client.Close()

	session, _ := client.NewSession()
    defer session.Close()
    
    // Copy!
    err := scp.Copy(session, "/path/to/local/file", "/path/to/remote/file")
    
    if err != nil {
    panic(err)
    }
}

The behavior is same as scp [-r] /path/to/local/file remote-addr:/path/to/remote/file

Custom Use

Please read protocol_test.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = &Options{}

Functions

func ConvertFileModeToPermString

func ConvertFileModeToPermString(mode os.FileMode) string

func Copy

func Copy(session *ssh.Session, from, target string) error

Copy `from` to `target`

func CopyFile

func CopyFile(session *ssh.Session, file io.Reader, filename string, size int64, mode os.FileMode, target string) error

func CopyFolder

func CopyFolder(session *ssh.Session, from string, mode os.FileMode, target string) error

Types

type Options added in v1.1.0

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

func (*Options) Copy added in v1.1.0

func (o *Options) Copy(session *ssh.Session, from, target string) error

Copy `from` to `target`

func (*Options) CopyFile added in v1.1.0

func (o *Options) CopyFile(session *ssh.Session, file io.Reader, filename string, size int64, mode os.FileMode, target string) error

func (*Options) CopyFolder added in v1.1.0

func (o *Options) CopyFolder(session *ssh.Session, from string, mode os.FileMode, target string) error

func (*Options) NewClient added in v1.1.0

func (o *Options) NewClient(session *ssh.Session) (*RemoteClient, error)

func (*Options) ScpPath added in v1.1.0

func (o *Options) ScpPath(scpPath string) *Options

type RemoteClient

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

func NewClient

func NewClient(session *ssh.Session) (*RemoteClient, error)

func (*RemoteClient) Start

func (c *RemoteClient) Start(filename string, isDirectory bool) error

func (*RemoteClient) WriteDirectoryEnd

func (c *RemoteClient) WriteDirectoryEnd() error

func (*RemoteClient) WriteDirectoryStart

func (c *RemoteClient) WriteDirectoryStart(perm string, filename string) error

func (*RemoteClient) WriteFile

func (c *RemoteClient) WriteFile(perm string, size int64, filename string, data io.Reader) error

Jump to

Keyboard shortcuts

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