PySSHHelper


NamePySSHHelper JSON
Version 0.1.1 PyPI version JSON
download
home_page
SummaryPython library for executing commands interactively over SSH including sudo su - priveleges
upload_time2024-02-08 15:39:41
maintainer
docs_urlNone
authorMax
requires_python>=3.8,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/xeonvs/PySSHHelper?logo=github)](https://github.com/xeonvs/PySSHHelper/releases) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
<!-- [![Pypi_Version](https://img.shields.io/pypi/v/PySSHHelper.svg)](https://pypi.python.org/pypi/PySSHHelper) -->
<!-- [![Downloads](https://static.pepy.tech/personalized-badge/PySSHHelper?period=total&units=international_system&left_color=black&right_color=blue&left_text=Downloads)](https://pepy.tech/project/PySSHHelper) -->

Please note that the project is in beta phase. Please report any issues you encounter or suggestions you have. We will do our best to address them quickly. Contributions are very welcome!

# PySSHHelper
PySSHHelper is a Python library for simplifying SSH connections and interactions with remote servers.

## Installation
You can install PySSHHelper using pip:

```shell
pip install PySSHHelper
```

If you would like the most up-to-date version, you can instead install directly from GitHub:
```shell
git clone <copied link from github>
cd PySSHHelper
pip install .
```

### Example of usage
```python
from PySSHHelper import SSHConnection
```

After importing the package, you can use SSHConnection in your code:
```python
# Create an SSH connection object
ssh = SSHConnection(
    host='your_host',
    port=22,
    username_ssh='your_ssh_username',
    password_ssh='your_ssh_password',
    username_sudo='your_sudo_username',
    password_sudo='your_sudo_password',
    verbose=True  # Set verbose to True for debugging information
)

# Connect to the SSH server
ssh.connect()

# Execute a command
output = ssh.execute_command("ls -l")
print(output)
```

The output variable will contain all output in the console, including escape codes from the terminal, you can use the method to clear them:
```python
print(ssh.cleanup_escape_codes(output))
```

If you want to execute commands in sudo context:
```python
ssh.elevate_privileges()
print(ssh.execute_command("echo 123 && sleep 5 && echo 321", timeout=10))
print(ssh.execute_command("id"))
```

And after you can revoke privileges and then continue to execute in normal context
```python
ssh.revoke_privileges()
print(ssh.execute_command("id"))
```

Also, you can do some SFTP operations
```python
print(ssh.list_directory())
ssh.sftp_get('/remote/path/file.txt', 'local_file.txt')
ssh.sftp_put('local_file.txt', '/remote/path/file.txt')
```

Close the SSH connection
```python
ssh.close()
```


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "PySSHHelper",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Max",
    "author_email": "PySSHHelper@proton.me",
    "download_url": "https://files.pythonhosted.org/packages/54/9d/f74ecac00540fda3c6fd39fb51806212e86f3a6a622b2124e95a4d6878fa/pysshhelper-0.1.1.tar.gz",
    "platform": null,
    "description": "[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/xeonvs/PySSHHelper?logo=github)](https://github.com/xeonvs/PySSHHelper/releases) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n<!-- [![Pypi_Version](https://img.shields.io/pypi/v/PySSHHelper.svg)](https://pypi.python.org/pypi/PySSHHelper) -->\n<!-- [![Downloads](https://static.pepy.tech/personalized-badge/PySSHHelper?period=total&units=international_system&left_color=black&right_color=blue&left_text=Downloads)](https://pepy.tech/project/PySSHHelper) -->\n\nPlease note that the project is in beta phase. Please report any issues you encounter or suggestions you have. We will do our best to address them quickly. Contributions are very welcome!\n\n# PySSHHelper\nPySSHHelper is a Python library for simplifying SSH connections and interactions with remote servers.\n\n## Installation\nYou can install PySSHHelper using pip:\n\n```shell\npip install PySSHHelper\n```\n\nIf you would like the most up-to-date version, you can instead install directly from GitHub:\n```shell\ngit clone <copied link from github>\ncd PySSHHelper\npip install .\n```\n\n### Example of usage\n```python\nfrom PySSHHelper import SSHConnection\n```\n\nAfter importing the package, you can use SSHConnection in your code:\n```python\n# Create an SSH connection object\nssh = SSHConnection(\n    host='your_host',\n    port=22,\n    username_ssh='your_ssh_username',\n    password_ssh='your_ssh_password',\n    username_sudo='your_sudo_username',\n    password_sudo='your_sudo_password',\n    verbose=True  # Set verbose to True for debugging information\n)\n\n# Connect to the SSH server\nssh.connect()\n\n# Execute a command\noutput = ssh.execute_command(\"ls -l\")\nprint(output)\n```\n\nThe output variable will contain all output in the console, including escape codes from the terminal, you can use the method to clear them:\n```python\nprint(ssh.cleanup_escape_codes(output))\n```\n\nIf you want to execute commands in sudo context:\n```python\nssh.elevate_privileges()\nprint(ssh.execute_command(\"echo 123 && sleep 5 && echo 321\", timeout=10))\nprint(ssh.execute_command(\"id\"))\n```\n\nAnd after you can revoke privileges and then continue to execute in normal context\n```python\nssh.revoke_privileges()\nprint(ssh.execute_command(\"id\"))\n```\n\nAlso, you can do some SFTP operations\n```python\nprint(ssh.list_directory())\nssh.sftp_get('/remote/path/file.txt', 'local_file.txt')\nssh.sftp_put('local_file.txt', '/remote/path/file.txt')\n```\n\nClose the SSH connection\n```python\nssh.close()\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python library for executing commands interactively over SSH including sudo su - priveleges",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/xeonvs/PySSHHelper",
        "Issues": "https://github.com/xeonvs/PySSHHelper/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c64e14ad2e8e355cb8d37e9b23e1ac05490df9ee343d0b4049697bdf0c79e60a",
                "md5": "f4ecf9343588404af468da21a8dd232e",
                "sha256": "923145c2e2c0b34d84c93feea626e307caf26238a2463f599395420f0a554879"
            },
            "downloads": -1,
            "filename": "pysshhelper-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f4ecf9343588404af468da21a8dd232e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 5497,
            "upload_time": "2024-02-08T15:39:40",
            "upload_time_iso_8601": "2024-02-08T15:39:40.592496Z",
            "url": "https://files.pythonhosted.org/packages/c6/4e/14ad2e8e355cb8d37e9b23e1ac05490df9ee343d0b4049697bdf0c79e60a/pysshhelper-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "549df74ecac00540fda3c6fd39fb51806212e86f3a6a622b2124e95a4d6878fa",
                "md5": "7b08b954c804e464de1b36aa1cbe8e68",
                "sha256": "08dd64abbaf7e64f542081766f82a2ba856e81295d549fbe1d1e72bd33ef6cd5"
            },
            "downloads": -1,
            "filename": "pysshhelper-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7b08b954c804e464de1b36aa1cbe8e68",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 4630,
            "upload_time": "2024-02-08T15:39:41",
            "upload_time_iso_8601": "2024-02-08T15:39:41.880006Z",
            "url": "https://files.pythonhosted.org/packages/54/9d/f74ecac00540fda3c6fd39fb51806212e86f3a6a622b2124e95a4d6878fa/pysshhelper-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-08 15:39:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "xeonvs",
    "github_project": "PySSHHelper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pysshhelper"
}
        
Max
Elapsed time: 0.21748s