scpw

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 21 Imported by: 0

README

scpw

GitHub GitHub tag (latest by date) Coverage Status

scp client wrapper for automatic put or get.

usage

install

use go get

go get -u github.com/T-TRz879/scpw/cmd/scpw

config

config file load in following order:

  • ~/.scpw
  • ~/.scpw.yml
  • ~/.scpw.yaml

config example:

# To upload or download all the content in the directory(Exclude Root Directory), simply add the*
# (example: download /tmp -> /tmp/*)
- name: serverA
  user: appAdmin
  host: 10.0.16.18
  port: 22
  password: 123456
  type: PUT
  lr-map:
  # Put all content under /tmp to the remote /tmp/A directory
  - { local: /tmp/* , remote: /tmp/A/ }
  - { local: /tmp/a.txt , remote: /tmp/b.txt }

# Remote folders must end with /
- name: serverB
  user: appAdmin
  host: 10.0.16.17
  port: 22
  password: 123456
  type: GET
  lr-map:
  # Get all content from remote /root/lib to the local /home/appAdmin directory
  - { local: /home/appAdmin/ , remote: /root/lib/ }
  - { local: /home/appAdmin/redis.conf , remote: /root/redis.conf }

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ONCE_LEN = 128 * 1024

Functions

func Addr

func Addr(ip, port string) string

func DisableLogColor

func DisableLogColor()

func FileModeV1

func FileModeV1(root string) (string, error)

func FileModeV2

func FileModeV2(file os.FileInfo) string

func GetLogger

func GetLogger(name string) *logHandle

GetLogger returns a logger mapped to `name`

func LoadConfigBytes

func LoadConfigBytes(names ...string) ([]byte, error)

func MaxInt

func MaxInt(a, b int) int

func MaxInt64

func MaxInt64(a, b int64) int64

func MinInt

func MinInt(a, b int) int

func MinInt64

func MinInt64(a, b int64) int64

func NewSSH

func NewSSH(node *Node) (*ssh.Client, error)

func ParseInt64

func ParseInt64(str string) (int64, error)

func ParseUnit32

func ParseUnit32(str string) (uint32, error)

func RandName

func RandName(root string) string

func SetLogLevel

func SetLogLevel(lvl logrus.Level)

SetLogLevel sets Level to all the loggers in the map

func SetOutFile

func SetOutFile(name string)

func SetOutput

func SetOutput(w io.Writer)

func StatDir

func StatDir(root string) (entries []os.DirEntry, name, mode, atime, mtime string, isDir bool, err error)

func StatDirChild

func StatDirChild(root string) ([]os.DirEntry, error)

func StatDirMeta

func StatDirMeta(root string) (name, mode, atime, mtime string, isDir bool, err error)

func StatFile

func StatFile(root string) (name string, mode string, atime string, mtime string, size string, err error)

func StatTimeV2

func StatTimeV2(file os.FileInfo) (string, string)

func WalkTree

func WalkTree(ctx Context, scpChan *scpChan, rootParent, root, dstPath string) error

Types

type Attr

type Attr struct {
	Name  string
	Mode  os.FileMode
	Size  int64
	Atime time.Time
	Mtime time.Time
	Typ   CommandType
}

func (*Attr) SetMode

func (a *Attr) SetMode(str string) error

func (*Attr) SetSize

func (a *Attr) SetSize(str string) error

func (*Attr) SetTime

func (a *Attr) SetTime(aStr, mStr string) error

type CommandType

type CommandType = string
const (
	C    CommandType = "C"
	D    CommandType = "D"
	E    CommandType = "E"
	T    CommandType = "T"
	NULL CommandType = "NULL"
)

type Context added in v1.0.1

type Context struct {
	Ctx context.Context
	Bar *mpb.Bar
}

type File

type File struct {
	Name       string
	LocalPath  string
	RemotePath string
	Mode       string
	Atime      string
	Mtime      string
	Size       string
	IsDir      bool
}

func NewFile

func NewFile(name, localPath, remotePath, mode, atime, mtime, size string, dir bool) File

type LRMap

type LRMap struct {
	Local  string `yaml:"local"`
	Remote string `yaml:"remote"`
}

type Node

type Node struct {
	Name     string   `yaml:"name"`
	Host     string   `yaml:"host"`
	User     string   `yaml:"user"`
	Port     string   `yaml:"port"`
	KeyPath  string   `yaml:"keypath"`
	Password string   `yaml:"password"`
	Children []*Node  `yaml:"children"`
	LRMap    []LRMap  `yaml:"lr-map"`
	Typ      SCPWType `yaml:"type"`
}

func LoadConfig

func LoadConfig() ([]*Node, error)

type Progress added in v1.0.1

type Progress struct {
	*mpb.Progress
	// contains filtered or unexported fields
}

func NewProgress added in v1.0.1

func NewProgress() *Progress

func (*Progress) NewInfiniteByesBar added in v1.0.1

func (p *Progress) NewInfiniteByesBar(name string) *mpb.Bar

type SCP

type SCP struct {
	*ssh.Client
	KeepTime   bool
	TimeOption string
}

func NewSCP

func NewSCP(cli *ssh.Client, keepTime bool) *SCP

func (*SCP) Get

func (scp *SCP) Get(ctx Context, srcPath, dstPath string) error

func (*SCP) GetAll

func (scp *SCP) GetAll(ctx Context, localPath, remotePath string) error

func (*SCP) Put

func (scp *SCP) Put(ctx Context, srcPath, dstPath string) error

func (*SCP) PutAll

func (scp *SCP) PutAll(ctx Context, srcPath, dstPath string) error

func (*SCP) PutAllExcludeRoot

func (scp *SCP) PutAllExcludeRoot(ctx Context, srcPath, dstPath string) error

func (*SCP) SwitchScpwFunc

func (scp *SCP) SwitchScpwFunc(ctx Context, localPath, remotePath string, typ SCPWType) error

type SCPWType

type SCPWType = string
const (
	PUT SCPWType = "PUT"
	GET SCPWType = "GET"
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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