{"id":36910030,"url":"https://github.com/rinetd/ssh","last_synced_at":"2026-01-12T15:57:30.638Z","repository":{"id":57557234,"uuid":"155337226","full_name":"rinetd/ssh","owner":"rinetd","description":"golang ssh lib 远程执行命令，文件上传下载 模仿rsync和cp","archived":false,"fork":false,"pushed_at":"2019-03-12T09:12:55.000Z","size":52,"stargazers_count":38,"open_issues_count":2,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-28T03:05:17.925Z","etag":null,"topics":["go","golang","lib","library","ssh"],"latest_commit_sha":null,"homepage":"https://github.com/rinetd/ssh","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rinetd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-30T06:42:31.000Z","updated_at":"2024-12-17T08:57:25.000Z","dependencies_parsed_at":"2022-09-07T22:23:36.549Z","dependency_job_id":null,"html_url":"https://github.com/rinetd/ssh","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rinetd/ssh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinetd%2Fssh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinetd%2Fssh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinetd%2Fssh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinetd%2Fssh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rinetd","download_url":"https://codeload.github.com/rinetd/ssh/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinetd%2Fssh/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28341888,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T15:50:39.657Z","status":"ssl_error","status_checked_at":"2026-01-12T15:49:49.297Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","lib","library","ssh"],"created_at":"2026-01-12T15:57:30.429Z","updated_at":"2026-01-12T15:57:30.576Z","avatar_url":"https://github.com/rinetd.png","language":"Go","readme":"\n## 项目简介\n本项目是基于golang标准库 ssh 和 sftp 开发\n\n本项目是对标准库进行一个简单的高层封装,使得可以在在 Windows Linux Mac 上非常容易的执行 ssh 命令,\n以及文件,文件夹的上传,下载等操作.\n1. 当src 为目录时\n文件上传下载模仿rsync: 只和源有关.  \n// rsync -av src/ dst     ./src/* --\u003e /root/dst/*  \n// rsync -av src/ dst/    ./src/* --\u003e /root/dst/*  \n// rsync -av src  dst     ./src/* --\u003e /root/dst/src/*  \n// rsync -av src  dst/    ./src/* --\u003e /root/dst/src/*  \n2. 当src 为文件时\n当dst为目录，以\"/\"结尾，则自动拼接上文件名\n当dst为文件，不以“/”结尾时，则重命名文件\n## Install\n`go get github.com/pytool/ssh`\n## Example\n\n### 在远程执行ssh命令\n提供3个方法: Run() Exec() Output() \n1. Run() : 程序执行后,不再受执行者控制. 适用于启动服务端进程.\n2. Exec() : 在控制台同步实时输出程序的执行结果.\n3. Output() : 会等待程序执行完成后,输出执行结果,在需要对执行的结果进行操作时使用.\n```go\npackage main\nimport (\n\t\"fmt\"\n\t\"github.com/pytool/ssh\"\n)\nfunc main() {\n\n\tc, err := ssh.NewClient(\"localhost\", \"22\", \"root\", \"ubuntu\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer c.Close()\n\n\toutput, err := c.Output(\"uptime\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"Uptime: %s\\n\", output)\n}\n\n```\n### 文件下载\n```go\npackage main\n\nimport (\n\t\"github.com/pytool/ssh\"\n)\n\nfunc main() {\n\n\tclient, err := ssh.NewClient( \"localhost\", \"22\", \"root\", \"ubuntu\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer client.Close()\n\tvar remotedir = \"/root/test/\"\n\t// download dir\n\tvar local = \"/home/ubuntu/go/src/github.com/pytool/ssh/test/download/\"\n\tclient.Download(remotedir, local)\n\n\t// upload file\n\tvar remotefile = \"/root/test/file\"\n\n\tclient.Download(remotefile, local)\n}\n\n```\n\n### 文件上传\n```go\npackage main\n\nimport (\n\t\"github.com/pytool/ssh\"\n)\n\nfunc main() {\n\n\tclient, err := ssh.NewClient( \"localhost\", \"22\", \"root\", \"ubuntu\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer client.Close()\n\tvar remotedir = \"/root/test/\"\n\t// upload dir\n\tvar local = \"/home/ubuntu/go/src/github.com/pytool/ssh/test/upload/\"\n\tclient.Upload(local, remotedir)\n\n\t// upload file\n\tlocal = \"/home/ubuntu/go/src/github.com/pytool/ssh/test/upload/file\"\n\tclient.Upload(local, remotedir)\n}\n\n```\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frinetd%2Fssh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frinetd%2Fssh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frinetd%2Fssh/lists"}