All Projects → rinetd → ssh

rinetd / ssh

Licence: Apache-2.0 license
golang ssh lib 远程执行命令,文件上传下载 模仿rsync和cp

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to ssh

Yamaha Nodejs
A node module to control your yamaha receiver
Stars: ✭ 103 (+255.17%)
Mutual labels:  lib
Mtproto Core
Telegram API JS (MTProto) client library for browser and nodejs
Stars: ✭ 242 (+734.48%)
Mutual labels:  lib
metalsmith-imagemin
Metalsmith plugin to minify images
Stars: ✭ 17 (-41.38%)
Mutual labels:  lib
Math Engine
Mathematical expression parsing and calculation engine library. 数学表达式解析计算引擎库
Stars: ✭ 123 (+324.14%)
Mutual labels:  lib
Weworkapi php
official lib of wework api
Stars: ✭ 225 (+675.86%)
Mutual labels:  lib
impromptu.nvim
Create prompts fast and easy
Stars: ✭ 39 (+34.48%)
Mutual labels:  lib
Imageselector
图片选择器, 支持多图选择和图片预览
Stars: ✭ 62 (+113.79%)
Mutual labels:  lib
SunriseSunset
Java utility to calculate the time of sunrise and sunset for a given location.
Stars: ✭ 42 (+44.83%)
Mutual labels:  lib
Stdlib
✨ Standard library for JavaScript and Node.js. ✨
Stars: ✭ 2,749 (+9379.31%)
Mutual labels:  lib
tgcalls
Voice chats, private incoming and outgoing calls in Telegram for Developers
Stars: ✭ 408 (+1306.9%)
Mutual labels:  lib
Vue Loaders
Vue + loaders.css
Stars: ✭ 127 (+337.93%)
Mutual labels:  lib
React Scoped Css
CSS encapsulation solution for React
Stars: ✭ 214 (+637.93%)
Mutual labels:  lib
Mal4J
Java wrapper for the official MyAnimeList API
Stars: ✭ 23 (-20.69%)
Mutual labels:  lib
Dtkwidget
Deepin Toolkit, widget module for DDE look and feel
Stars: ✭ 112 (+286.21%)
Mutual labels:  lib
gostreamer
Go example that uses channels to build an execution pipeline
Stars: ✭ 75 (+158.62%)
Mutual labels:  lib
Appmetrics.js
A small (< 1kb) library for measuring things in your web app and reporting the results to Google Analytics.
Stars: ✭ 1,383 (+4668.97%)
Mutual labels:  lib
rawhttp
Raw HTTP client in Go for complete request control and customization.
Stars: ✭ 100 (+244.83%)
Mutual labels:  lib
epub-parser
A powerful yet easy-to-use epub parser
Stars: ✭ 103 (+255.17%)
Mutual labels:  lib
telegram
Golang Telegram Bot API
Stars: ✭ 13 (-55.17%)
Mutual labels:  lib
AltiumLibrary
Useful Altium pcb library (3D)
Stars: ✭ 33 (+13.79%)
Mutual labels:  lib

项目简介

本项目是基于golang标准库 ssh 和 sftp 开发

本项目是对标准库进行一个简单的高层封装,使得可以在在 Windows Linux Mac 上非常容易的执行 ssh 命令, 以及文件,文件夹的上传,下载等操作.

  1. 当src 为目录时 文件上传下载模仿rsync: 只和源有关.
    // rsync -av src/ dst ./src/* --> /root/dst/*
    // rsync -av src/ dst/ ./src/* --> /root/dst/*
    // rsync -av src dst ./src/* --> /root/dst/src/*
    // rsync -av src dst/ ./src/* --> /root/dst/src/*
  2. 当src 为文件时 当dst为目录,以"/"结尾,则自动拼接上文件名 当dst为文件,不以“/”结尾时,则重命名文件

Install

go get github.com/pytool/ssh

Example

在远程执行ssh命令

提供3个方法: Run() Exec() Output()

  1. Run() : 程序执行后,不再受执行者控制. 适用于启动服务端进程.
  2. Exec() : 在控制台同步实时输出程序的执行结果.
  3. Output() : 会等待程序执行完成后,输出执行结果,在需要对执行的结果进行操作时使用.
package main
import (
	"fmt"
	"github.com/pytool/ssh"
)
func main() {

	c, err := ssh.NewClient("localhost", "22", "root", "ubuntu")
	if err != nil {
		panic(err)
	}
	defer c.Close()

	output, err := c.Output("uptime")
	if err != nil {
		panic(err)
	}

	fmt.Printf("Uptime: %s\n", output)
}

文件下载

package main

import (
	"github.com/pytool/ssh"
)

func main() {

	client, err := ssh.NewClient( "localhost", "22", "root", "ubuntu")
	if err != nil {
		panic(err)
	}
	defer client.Close()
	var remotedir = "/root/test/"
	// download dir
	var local = "/home/ubuntu/go/src/github.com/pytool/ssh/test/download/"
	client.Download(remotedir, local)

	// upload file
	var remotefile = "/root/test/file"

	client.Download(remotefile, local)
}

文件上传

package main

import (
	"github.com/pytool/ssh"
)

func main() {

	client, err := ssh.NewClient( "localhost", "22", "root", "ubuntu")
	if err != nil {
		panic(err)
	}
	defer client.Close()
	var remotedir = "/root/test/"
	// upload dir
	var local = "/home/ubuntu/go/src/github.com/pytool/ssh/test/upload/"
	client.Upload(local, remotedir)

	// upload file
	local = "/home/ubuntu/go/src/github.com/pytool/ssh/test/upload/file"
	client.Upload(local, remotedir)
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].