Skip to main content

SSH-Lite

An easy encapsulation for paramiko library which contains only common operations, useful for automatic test and CI/CD deploy.

Updates:

  • Version 1.9 supports python2 code for old projects.

  • Version 1.7 is a bugfix version that fixes bugs in doc and lower the chance of messy code (bc multi bytes character splits into different segments).

  • Version 1.5 is a bugfix version that handles possible UnicodeEncodeError of terminal output when using an actually bytesIO terminal as debug_file (i.e. stdout).

  • Version 1.4 is an enhance version that supports debug info redirection and expect-fail-assertion.

  • Version 1.2 is a bugfix version that supports servers without SFTP service (e.g. Gateway Servers).

Features

  • Interactive shell commands without blocking

    • send for sending a command only

    • send_and_read is the most common, for sending a command and read all returnes in a timeout period (timeout will be updated after receiving any bytes)

    • get_buff for reading all buffers from the terminal in a timeout period

  • Uploading or downloading files between local and remote server

  • Expect function (may raise an exception for timeout or any unexpect pattern you set)

  • Grep function and keys abbreviations

  • Output redirection

QuickStart

install

pip install ssh-lite

or update

pip install -U ssh-lite

a simple example

from ssh_lite import Server

ci = Server("127.0.0.1", "123456", "root")
ci.send_and_read("")    # waiting connection output done, avoid getting extra output before "ls -l" like "Last login: Tue ..."
print(ci.send_and_read("ls -l"))
del ci

the effect is like

ls -l
total 1736
-rw-r--r-- 1 root  root  1775417 Aug 25  2019 get-pip.py
-rwxrwxrwx 1 root  root      289 Feb 20 12:00 temp.py
-rwxrwxrwx 1 root  root      136 Nov 22 21:18 upload

another little complex example to explain the functions

from ssh_lite import Server, KeyAbbr

remote = "/docker_binding_path"
file = "test.file"

with Server("127.0.0.1", "123456", "root", port=22, key_path=None) as ci:  # type: Server  # rsa keys are supported
    ci.debug = True     # to see server inputs and outputs
    ci.get_file("/a_log_file_to_get", ".")      # getting files doesn't need destination filename
    ci.send_and_read("mkdir -p " + remote, timeout=1)
    ci.send_and_read("rm -f {}*".format(remote), timeout=1)
    ci.put_file("prepare/" + file, remote + file)      # putting files strictly need destination filename
    ci.send_and_read("", timeout=1)
    cmd = 'docker exec -i container_name curl -v "http://127.0.0.1:9990/upload?file=/reference_path/{}&uri=me"'.format(
        file)
    print("inner cmd is: {}".format(cmd))
    ci.send(cmd)
    ci.expect("< HTTP/1.1 200 OK", timeout=30, failpat=["< HTTP/1.1 4", "< HTTP/1.1 5"])
    # will raise an exception if we cannot see 200 OK response in 30 secs or if we find any 4xx 5xx response
    ci.send(KeyAbbr.CTRL_C, end="")      # sending a CTRL+C to exit the HTTP2 long connection
    ci.send('exit')       # exit from container to release the connection

Bug report

  • Issues and bugs report to rainydew@qq.com.

  • Homepage icon leads to my Github project page, issues / PRs / stars are welcomed :)

Release files for ssh-lite 1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ssh-lite 1.9
File Size Uploaded
ssh-lite-1.9.tar.gz 5.5 kB Details

Release files / ssh-lite-1.9.tar.gz

Download URL ssh-lite-1.9.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5b5e8d5747153cfbd72d5433ae87ce80d9ffd53101bc34d47099b40c79fa991b
BLAKE2b-256 checksum
How to use checksums
d6980135ccfc8c011dd37ce953e2454c1c7f61d7903c22542e61b0fc38ac6537
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release history Release notifications | RSS feed

This release

1.9 This release

1 release file

1.7

1 release file

1.5

1 release file

1.4

1 release file

1.2

1 release file

1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page