Skip to main content

Overview

This module was inspired by the SFTP for Sublime Text plugin.

As such, it facilitates interacting with remote hosts via ssh,
with the added bonus of providing a means to mirror your local
working directory to the specified path on the remote host in order
to facilitate local-edit/remote-build.

With this module you can:

  • Edit and manipulate your scripts locally and execute them remotely,
    with file synchronization capabilities
  • Map a local folder to a remote folder

Prerequisites:

  • Python 3.7+
  • paramiko
  • If working with git repos, the module requires that git be installed locally and remotely

Installation

  • From pypi: pip3 install bertdotssh
  • From this git repo: pip3 install git+https://github.com/berttejeda/bert.sshutil.git
    Note: To install a specific version of the library from this git repo,
    suffix the git URL in the above command with @{ tag name }, e.g.:
    git+https://github.com/berttejeda/bert.sshutil.git@1.0.0

Usage Examples

Get process status for a remote host via ssh

from bertdotssh.provider import RemoteCLIProvider

settings = {
  'host': 'myhost.example.local', 
  'remote_path': '/home/myusername',
  'port': 22, 
  'ssh_key_file': '~/.ssh/id_rsa', 
  'user': 'myusername'
}

remote = RemoteCLIProvider(settings)

remote.run('ps')

Syncronize local files to remote and run a local script against the same host

Given:

  • Local working directory: /home/myusername/some/path
  • Local script: myscript.sh
from bertdotssh.provider import RemoteCLIProvider

settings = {
  'host': 'myhost.example.local', 
  'remote_path': '/home/myusername',
  'port': 22, 
  'ssh_key_file': '~/.ssh/id_rsa', 
  'user': 'myusername',
  'sync_no_clobber': True,
  'sync_on': True  
}

remote = RemoteCLIProvider(settings)

remote.run('myscript.sh')

Syncronize local git repo to remote and run a local script against the same host

Given:

  • Local working directory (a git repo) at: /home/myusername/some/git/myrepo
  • Local script at: /home/myusername/some/git/myrepo/myscript.sh
  • Git repo on remote host at: /home/myusername/some/other/path/git/myrepo
from bertdotssh.provider import RemoteCLIProvider

settings = {
  'host': 'myhost.example.local', 
  'remote_path': '/home/myusername/some/other/path/git/myrepo',
  'port': 22, 
  'ssh_key_file': '~/.ssh/id_rsa', 
  'user': 'myusername',
  'sync_no_clobber': True,
  'sync_on': True  
}

remote = RemoteCLIProvider(settings)

remote.run('myscript.sh',
  git_username='my_git_username', 
  git_password='my_git_password')

File syncrhonization behavior

The above example scenarios exhibit the following programmatic behavior upon sync:

  1. Determine if local working directory is a git repo
  • If True
    • Determine the URL for the git remote via command git config --get remote.origin.url
    • Determine the paths for any locally changed files via command git diff-index HEAD --name-status
    • Determine the paths for any untracked files via command git ls-files --others --exclude-standard
    • Produce a list of files to sync by combining the output of the above two commands
  • If False
    • Produce a list of files to sync that have changed within the last 5 minutes
  1. Determine if remote path exists
  • If False
    • If local is a git repo
      • Perform a git clone of the git repo against the remote path
      • Else, create the remote directory and synchronize the file list across the remote
  • If True, determines if remote path is a git repo
    • Determine set of files that have changed in the remote path
    • If True & sync_no_clobber == True, synchronize locally changed
      files to remote path, skipping any files that have also changed on the remote
    • If True & sync_no_clobber == False, synchronize locally changed
      files to remote path, overwriting any files that have also changed on the remote

Metadata

Release files for btssh 1.2.0

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

Source distribution (sdist)

Source distribution for btssh 1.2.0
File Size Uploaded Provenance Actions
btssh-1.2.0.tar.gz 16.6 kB Without provenance Details for btssh-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for btssh 1.2.0
File Interpreter ABI Platform Actions
btssh-1.2.0-py3-none-any.whl Python 3 none any Details for btssh-1.2.0-py3-none-any.whl

Total release size: 32.0 kB

Release files / btssh-1.2.0.tar.gz

Download URL btssh-1.2.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5fc27ec6739cc08f38247053cf838defe1474bd20165c617274f5b2f63512a00
BLAKE2b-256 checksum
How to use checksums
3d10d2b97ce371daaa6ecff34480c667aa532f0a6df8e866b072e78bc3c1715b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Release files / btssh-1.2.0-py3-none-any.whl

Download URL btssh-1.2.0-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5631584939e0f808276b277fae54b42d6cfa0d1855a422f191d07bdea6dad14f
BLAKE2b-256 checksum
How to use checksums
5d4d09f46ff62a848ead185e2056f1761d01149e5388cfb1441d56c351418ab2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Security for btssh 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files No provenance

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