router

package
v0.0.0-...-683b059 Latest Latest
Warning

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

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

Documentation

Overview

Package router provides common local and remote utilities for accessing or controlling different routers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSingleFile

func GetSingleFile(ctx context.Context, host *ssh.Conn, srcRemoteFilePath, dstLocalFilePath string) (retErr error)

GetSingleFile copies a single file from the host to the local machine. srcRemoteFilePath is the full source file path on the host to be copied. dstLocalFilePath will be replaced if it already exists. The local file will be created with default permissions for the local machine.

Unlike linuxssh.GetFile, tar is not used to transfer the file and directories are not supported. This is because routers have varied support for tar. Instead, a simple cat call on the host is used and its stdout is directed to a local file.

func MakeDirs

func MakeDirs(ctx context.Context, host *ssh.Conn, dirs ...string) error

MakeDirs ensures directories on the remote host exist matching the absolute paths in dirs, creating any missing directories in each path.

Directories are created using "mkdir -p <path>". Since the "-p" flag creates any missing parent directories in the path as well, if one path in dirs would be a parent of another path in dirs the parent path is not explicitly created with mkdir. All directories are created using default permissions on the host.

func PutFiles

func PutFiles(ctx context.Context, host *ssh.Conn, files map[string]string) (int64, error)

PutFiles copies files on the local machine to the host. The files param 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. bytes is the amount of data sent over the wire. Local symbolic links are evaluated. All directories are created with the default permissions on the host.

Unlike linuxssh.PutFiles, tar is not used to transfer the files. This is because routers have varied support for tar. Instead, each file is read and written directly with linuxssh.WriteFile using the same permissions as the source file. Also unlike linuxssh.PutFiles, no file compression is used and all files are always written.

Types

This section is empty.

Jump to

Keyboard shortcuts

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