Usage examples

Simple command execution

>>> import pyssh
>>> s = pyssh.new_session(hostname="localhost", port="22")
>>> r = s.execute("uname -a")
>>> r.as_bytes()
b'Linux vaio.niwi.be 3.5.3-1-ARCH #1 SMP PREEMPT Sun Aug 26 09:14:51 CEST 2012 x86_64 GNU/Linux\n'
>>> r.return_code
0

Random access on remote file with sftp

>>> import os
>>> import pyssh
>>> session = pyssh.new_session(hostname="localhost")
>>> sftp = session.create_sftp()
>>> f = sftp.open("/tmp/some-file", (os.O_RDWR | os.O_CREAT))
>>> f.tell()
0
>>> f.write(b'Hello World')
>>> f.tell()
11
>>> f.seek(0)
True
>>> f.read(5)
b'Hello'
>>> f.read()
b' World'