Skip to content

Commit

Permalink
updating gh-pages repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsin Yuan Yeh authored and Hsin Yuan Yeh committed Oct 21, 2023
1 parent a43360d commit f9e8928
Show file tree
Hide file tree
Showing 4 changed files with 565 additions and 310 deletions.
5 changes: 4 additions & 1 deletion v2/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Last Updated on 2023/10/21
* 2023/10/17: [v2.0.2 Release Notes](release-v2.0.2)

## Tutorial
* [Core Features](tutorial)
* [Commands Execution and Console](tutorial)
* [Su and Sudo Console](tutorial-sudo)
* [Interactive Commands and Foreground Commands](tutorial-sudo)
* [Upload and Download Files](tutorial-download)
* [Threading Support](tutorial-threading)

### SSHScript v2.0 is still under development. If you find any bugs or have any suggestions, you are welcome to post them on the `issues` page.
Expand Down
93 changes: 93 additions & 0 deletions v2/tutorial-download.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# SSHScript v2.0 Core Features

Last Updated on 2023/10/20

<div style="text-align:right;position:relative;top:-140px"><a href="./index">Back to Index</a></div>

## Topics

* [Upload : $.upload()](#dollar-upload)
* [Download : $.download()](#dollar-download)


## πŸ”΅ <a name="dollar-upload"></a>Upload: $.upload()

### πŸŒŽοΌ„ Upload files to remote host using the SSHScript dollar-syntax
```
## filename: example.spy
## run: sshscript example.spy
import os
assert os.path.exists('image.jpg')
with $.connect('user@host','1234') as host:
host.upload('image.jpg','imageuploaded.jpg')
host('[ -e "$PWD"/imageuploaded.jpg ]')
assert host.exitcode == 0
## move the uploaded file to /root
with host.sudo('1234') as sudo:
sudo('cp imageuploaded.jpg /root')
sudo('[ -e /root/imageuploaded.jpg ]')
assert sudo.exitcode == 0
```

### 🌎🐍 Upload files to remote host using the SSHScript module

```
## filename: example.py
## run: python3 example.py
import sshscript
session = sshscript.SSHScriptSession()
import os
assert os.path.exists('image.jpg')
with session.connect('user@host','1234') as host:
host.upload('image.jpg','imageuploaded.jpg')
host('[ -e "$PWD"/imageuploaded.jpg ]')
assert host.exitcode == 0
## move the uploaded file to /root
with host.sudo('1234') as sudo:
sudo('cp imageuploaded.jpg /root')
sudo('[ -e /root/imageuploaded.jpg ]')
assert sudo.exitcode == 0
```
## πŸ”΅ <a name="dollar-download"></a>Download: $.download()

### πŸŒŽοΌ„ Download files from remote host using the SSHScript dollar-syntax
```
## filename: example.spy
## run: sshscript example.spy
import os
with $.connect('user@host','1234') as host:
$[ -e "$PWD"/image.jpg ]
assert $.exitcode == 0
host.download('image.jpg','imagedownloaded.jpg')
## check downloaded file on localhost
$[ -e imagedownloaded.jpg ]
assert $.exitcode == 0
```

### 🌎🐍 Download files from remote host using the SSHScript module

```
## filename: example.py
## run: python3 example.py
import sshscript
session = sshscript.SSHScriptSession()
import os
with session.connect('user@host','1234') as host:
## check source file on remote host
host('[ -e "$PWD"/image.jpg ]')
assert host.exitcode == 0
host.download('image.jpg','imagedownloaded.jpg')
## check downloaded file on localhost
session('[ -e imagedownloaded.jpg ]')
assert session.exitcode == 0
```

### Symbols

- ⏚ : local

- 🌎 : remote

- οΌ„ : SSHScript dollar-syntax

- 🐍 : SSHScript module
Loading

0 comments on commit f9e8928

Please sign in to comment.