linuxssh

package
v0.0.0-...-b5d9cbe Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package linuxssh provides Linux specific operations conducted via SSH TODO(oka): now that this file is not used from framework, simplify the code.

Index

Constants

View Source
const (
	// PreserveSymlinks indicates that symlinks should be preserved during the copy.
	PreserveSymlinks = linuxssh.PreserveSymlinks
	// DereferenceSymlinks indicates that symlinks should be dereferenced and turned into normal files.
	DereferenceSymlinks = linuxssh.DereferenceSymlinks
)

Variables

This section is empty.

Functions

func GetFile

func GetFile(ctx context.Context, s *ssh.Conn, src, dst string, symlinkPolicy SymlinkPolicy) error

GetFile copies a file or directory from the host to the local machine. dst is the full destination name for the file or directory being copied, not a destination directory into which it will be copied. dst will be replaced if it already exists.

func GetFileTail

func GetFileTail(ctx context.Context, conn *ssh.Conn, src, dst string, startLine, maxSize int64) error

GetFileTail reads the file on the path and returns the file truncate by command tail with the Max System Message Log Size and destination.

func PutFiles

func PutFiles(ctx context.Context, s *ssh.Conn, files map[string]string,
	symlinkPolicy SymlinkPolicy) (bytes int64, err error)

PutFiles copies files on the local machine to the host. files describes a mapping from a local file path to a remote file path. For example, the call:

PutFiles(ctx, conn, map[string]string{"/src/from": "/dst/to"})

will copy the local file or directory /src/from to /dst/to on the remote host. Local file paths can be absolute or relative. Remote file paths must be absolute. SHA1 hashes of remote files are checked in advance to send updated files only. bytes is the amount of data sent over the wire (possibly after compression).

func ReadFile

func ReadFile(ctx context.Context, conn *ssh.Conn, path string) ([]byte, error)

ReadFile reads the file on the path and returns the contents.

func WriteFile

func WriteFile(ctx context.Context, conn *ssh.Conn, path string, data []byte, perm os.FileMode) error

WriteFile writes data to the file on the path. If the file does not exist, WriteFile creates it with permissions perm; otherwise WriteFile truncates it before writing, without changing permissions. Unlike ioutil.WriteFile, it doesn't apply umask on perm.

Types

type RemoteFileDelta

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

RemoteFileDelta describes the result from the function NewRemoteFileDelta.

func NewRemoteFileDelta

func NewRemoteFileDelta(ctx context.Context, s *ssh.Conn, src, dst string, maxSize int64) (*RemoteFileDelta, error)

NewRemoteFileDelta get startline from LineCount create a object rtd with ssh connection, file source, file destination and file max size.

func (*RemoteFileDelta) Save

func (rtd *RemoteFileDelta) Save(ctx context.Context) error

Save calling the GetFileTail with struct RemoteFileDelta RemoteFileDelta the range between beginning of the file and rtd.startline will be truncated.

type SymlinkPolicy

type SymlinkPolicy = linuxssh.SymlinkPolicy

SymlinkPolicy describes how symbolic links should be handled by PutFiles.

type WordCountInfo

type WordCountInfo struct {
	Lines int64
	Words int64
	Bytes int64
}

WordCountInfo describes the result from the unix command wc.

func WordCount

func WordCount(ctx context.Context, conn *ssh.Conn, path string) (*WordCountInfo, error)

WordCount get the line, word and byte counts of a remote text file.

Jump to

Keyboard shortcuts

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