Skip to content

Commit 4c7b988

Browse files
committed
docs: update documentation for installation and WriteFile usage
- Add installation instructions and Go version requirements to the documentation - Fix typos related to argument naming and folder spelling - Clarify and correct usage example for the WriteFile method - Add a detailed WriteFile usage section and example in the Chinese documentation Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 43d69a4 commit 4c7b988

2 files changed

Lines changed: 56 additions & 4 deletions

File tree

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ This project is forked from [easyssh](https://github.com/hypersleep/easyssh) but
3232
192.168.1.5 121.1.2.3 10.10.29.68
3333
```
3434

35+
## Installation
36+
37+
```bash
38+
go get github.com/appleboy/easyssh-proxy
39+
```
40+
41+
**Requirements:** Go 1.24 or higher
42+
3543
## Usage
3644

3745
You can see detailed examples of the `ssh`, `scp`, `Proxy`, and `stream` commands inside the [`examples`](./_examples/) folder.
@@ -245,7 +253,7 @@ func main() {
245253
}
246254
```
247255

248-
### WiteFile
256+
### WriteFile
249257

250258
See [examples/writeFile/writeFile.go](./_examples/writeFile/writeFile.go)
251259

@@ -268,8 +276,8 @@ func main() {
268276
reader := strings.NewReader(fileContents)
269277

270278
// Write a file to the remote server using the writeFile command.
271-
// Second arguement specifies the number of bytes to write to the server from the reader.
272-
if err := client.WriteFile(reader, int64(len(fileContents)), "/home/user/foo.txt"); err != nil {
279+
// Second argument specifies the number of bytes to write to the server from the reader.
280+
if err := ssh.WriteFile(reader, int64(len(fileContents)), "/home/user/foo.txt"); err != nil {
273281
return fmt.Errorf("Error: failed to write file to client. error: %w", err)
274282
}
275283
}

README.zh-tw.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ easyssh-proxy 提供了一個用 Go 語言實現的一些 SSH 協議功能的簡
3030
192.168.1.5 121.1.2.3 10.10.29.68
3131
```
3232

33+
## 安裝
34+
35+
```bash
36+
go get github.com/appleboy/easyssh-proxy
37+
```
38+
39+
**需求:** Go 1.24 或更高版本
40+
3341
## 使用方法
3442

3543
你可以在 [`examples`](./_examples/) 資料夾中看到 `ssh``scp``Proxy``stream` 命令的詳細範例。
@@ -157,7 +165,7 @@ func main() {
157165
}
158166

159167
// Call Scp method with file you want to upload to remote server.
160-
// Please make sure the `tmp` floder exists.
168+
// Please make sure the `tmp` folder exists.
161169
err := ssh.Scp("/root/source.csv", "/tmp/target.csv")
162170

163171
// Handle errors
@@ -242,3 +250,39 @@ func main() {
242250
}
243251
}
244252
```
253+
254+
### WriteFile
255+
256+
參見 [examples/writeFile/writeFile.go](./_examples/writeFile/writeFile.go)
257+
258+
```go
259+
func (ssh_conf *MakeConfig) WriteFile(reader io.Reader, size int64, etargetFile string) error
260+
```
261+
262+
```go
263+
func main() {
264+
// 使用遠程用戶名、伺服器地址和私鑰路徑創建 MakeConfig 實例。
265+
ssh := &easyssh.MakeConfig{
266+
Server: "localhost",
267+
User: "drone-scp",
268+
KeyPath: "./tests/.ssh/id_rsa",
269+
Port: "22",
270+
Timeout: 60 * time.Second,
271+
}
272+
273+
fileContents := "Example Text..."
274+
reader := strings.NewReader(fileContents)
275+
276+
// 使用 writeFile 命令將文件寫入到遠程伺服器。
277+
// 第二個參數指定從 reader 中寫入到伺服器的字節數。
278+
if err := ssh.WriteFile(reader, int64(len(fileContents)), "/home/user/foo.txt"); err != nil {
279+
return fmt.Errorf("錯誤:無法將文件寫入到客戶端。錯誤:%w", err)
280+
}
281+
}
282+
```
283+
284+
| 屬性 | 描述 |
285+
| ----------- | --------------------------------------------- |
286+
| reader | 將讀取其內容並保存到伺服器的 `io.reader` |
287+
| size | 要從 `io.reader` 中讀取的字節數 |
288+
| etargetFile | 文件將被寫入到伺服器上的位置 |

0 commit comments

Comments
 (0)