-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hsin Yuan Yeh
authored and
Hsin Yuan Yeh
committed
Oct 21, 2023
1 parent
a43360d
commit f9e8928
Showing
4 changed files
with
565 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.