scp


Namescp JSON
Version 0.15.0 PyPI version JSON
download
home_pagehttps://github.com/jbardin/scp.py
Summaryscp module for paramiko
upload_time2024-05-23 21:37:41
maintainerRemi Rampin
docs_urlNone
authorJames Bardin
requires_pythonNone
licenseLGPL-2.1-or-later
keywords paramiko ssh scp transfer
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Pure python scp module
======================

The scp.py module uses a paramiko transport to send and receive files via the
scp1 protocol. This is the protocol as referenced from the openssh scp program,
and has only been tested with this implementation.


Example
-------

..  code-block:: python

    from paramiko import SSHClient
    from scp import SCPClient

    ssh = SSHClient()
    ssh.load_system_host_keys()
    ssh.connect('example.com')

    # SCPCLient takes a paramiko transport as an argument
    scp = SCPClient(ssh.get_transport())

    scp.put('test.txt', 'test2.txt')
    scp.get('test2.txt')

    # Uploading the 'test' directory with its content in the
    # '/home/user/dump' remote directory
    scp.put('test', recursive=True, remote_path='/home/user/dump')

    scp.close()


..  code-block::

    $ md5sum test.txt test2.txt
    fc264c65fb17b7db5237cf7ce1780769 test.txt
    fc264c65fb17b7db5237cf7ce1780769 test2.txt

Using 'with' keyword
--------------------

..  code-block:: python

    from paramiko import SSHClient
    from scp import SCPClient

    with SSHClient() as ssh:
        ssh.load_system_host_keys()
        ssh.connect('example.com')

        with SCPClient(ssh.get_transport()) as scp:
            scp.put('test.txt', 'test2.txt')
            scp.get('test2.txt')


..  code-block::

    $ md5sum test.txt test2.txt
    fc264c65fb17b7db5237cf7ce1780769 test.txt
    fc264c65fb17b7db5237cf7ce1780769 test2.txt


Uploading file-like objects
---------------------------

The ``putfo`` method can be used to upload file-like objects:

..  code-block:: python

    import io
    from paramiko import SSHClient
    from scp import SCPClient

    ssh = SSHClient()
    ssh.load_system_host_keys()
    ssh.connect('example.com')

    # SCPCLient takes a paramiko transport as an argument
    scp = SCPClient(ssh.get_transport())

    # generate in-memory file-like object
    fl = io.BytesIO()
    fl.write(b'test')
    fl.seek(0)
    # upload it directly from memory
    scp.putfo(fl, '/tmp/test.txt')
    # close connection
    scp.close()
    # close file handler
    fl.close()


Tracking progress of your file uploads/downloads
------------------------------------------------

A ``progress`` function can be given as a callback to the SCPClient to handle
how the current SCP operation handles the progress of the transfers. In the
example below we print the percentage complete of the file transfer.

..  code-block:: python

    from paramiko import SSHClient
    from scp import SCPClient
    import sys

    ssh = SSHClient()
    ssh.load_system_host_keys()
    ssh.connect('example.com')

    # Define progress callback that prints the current percentage completed for the file
    def progress(filename, size, sent):
        sys.stdout.write("%s's progress: %.2f%%   \r" % (filename, float(sent)/float(size)*100) )

    # SCPCLient takes a paramiko transport and progress callback as its arguments.
    scp = SCPClient(ssh.get_transport(), progress=progress)

    # you can also use progress4, which adds a 4th parameter to track IP and port
    # useful with multiple threads to track source
    def progress4(filename, size, sent, peername):
        sys.stdout.write("(%s:%s) %s's progress: %.2f%%   \r" % (peername[0], peername[1], filename, float(sent)/float(size)*100) )
    scp = SCPClient(ssh.get_transport(), progress4=progress4)

    scp.put('test.txt', '~/test.txt')
    # Should now be printing the current progress of your put function.

    scp.close()

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jbardin/scp.py",
    "name": "scp",
    "maintainer": "Remi Rampin",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": "remi@rampin.org",
    "keywords": "paramiko, ssh, scp, transfer",
    "author": "James Bardin",
    "author_email": "j.bardin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d6/1c/d213e1c6651d0bd37636b21b1ba9b895f276e8057f882c9f944931e4f002/scp-0.15.0.tar.gz",
    "platform": null,
    "description": "Pure python scp module\n======================\n\nThe scp.py module uses a paramiko transport to send and receive files via the\nscp1 protocol. This is the protocol as referenced from the openssh scp program,\nand has only been tested with this implementation.\n\n\nExample\n-------\n\n..  code-block:: python\n\n    from paramiko import SSHClient\n    from scp import SCPClient\n\n    ssh = SSHClient()\n    ssh.load_system_host_keys()\n    ssh.connect('example.com')\n\n    # SCPCLient takes a paramiko transport as an argument\n    scp = SCPClient(ssh.get_transport())\n\n    scp.put('test.txt', 'test2.txt')\n    scp.get('test2.txt')\n\n    # Uploading the 'test' directory with its content in the\n    # '/home/user/dump' remote directory\n    scp.put('test', recursive=True, remote_path='/home/user/dump')\n\n    scp.close()\n\n\n..  code-block::\n\n    $ md5sum test.txt test2.txt\n    fc264c65fb17b7db5237cf7ce1780769 test.txt\n    fc264c65fb17b7db5237cf7ce1780769 test2.txt\n\nUsing 'with' keyword\n--------------------\n\n..  code-block:: python\n\n    from paramiko import SSHClient\n    from scp import SCPClient\n\n    with SSHClient() as ssh:\n        ssh.load_system_host_keys()\n        ssh.connect('example.com')\n\n        with SCPClient(ssh.get_transport()) as scp:\n            scp.put('test.txt', 'test2.txt')\n            scp.get('test2.txt')\n\n\n..  code-block::\n\n    $ md5sum test.txt test2.txt\n    fc264c65fb17b7db5237cf7ce1780769 test.txt\n    fc264c65fb17b7db5237cf7ce1780769 test2.txt\n\n\nUploading file-like objects\n---------------------------\n\nThe ``putfo`` method can be used to upload file-like objects:\n\n..  code-block:: python\n\n    import io\n    from paramiko import SSHClient\n    from scp import SCPClient\n\n    ssh = SSHClient()\n    ssh.load_system_host_keys()\n    ssh.connect('example.com')\n\n    # SCPCLient takes a paramiko transport as an argument\n    scp = SCPClient(ssh.get_transport())\n\n    # generate in-memory file-like object\n    fl = io.BytesIO()\n    fl.write(b'test')\n    fl.seek(0)\n    # upload it directly from memory\n    scp.putfo(fl, '/tmp/test.txt')\n    # close connection\n    scp.close()\n    # close file handler\n    fl.close()\n\n\nTracking progress of your file uploads/downloads\n------------------------------------------------\n\nA ``progress`` function can be given as a callback to the SCPClient to handle\nhow the current SCP operation handles the progress of the transfers. In the\nexample below we print the percentage complete of the file transfer.\n\n..  code-block:: python\n\n    from paramiko import SSHClient\n    from scp import SCPClient\n    import sys\n\n    ssh = SSHClient()\n    ssh.load_system_host_keys()\n    ssh.connect('example.com')\n\n    # Define progress callback that prints the current percentage completed for the file\n    def progress(filename, size, sent):\n        sys.stdout.write(\"%s's progress: %.2f%%   \\r\" % (filename, float(sent)/float(size)*100) )\n\n    # SCPCLient takes a paramiko transport and progress callback as its arguments.\n    scp = SCPClient(ssh.get_transport(), progress=progress)\n\n    # you can also use progress4, which adds a 4th parameter to track IP and port\n    # useful with multiple threads to track source\n    def progress4(filename, size, sent, peername):\n        sys.stdout.write(\"(%s:%s) %s's progress: %.2f%%   \\r\" % (peername[0], peername[1], filename, float(sent)/float(size)*100) )\n    scp = SCPClient(ssh.get_transport(), progress4=progress4)\n\n    scp.put('test.txt', '~/test.txt')\n    # Should now be printing the current progress of your put function.\n\n    scp.close()\n",
    "bugtrack_url": null,
    "license": "LGPL-2.1-or-later",
    "summary": "scp module for paramiko",
    "version": "0.15.0",
    "project_urls": {
        "Homepage": "https://github.com/jbardin/scp.py"
    },
    "split_keywords": [
        "paramiko",
        " ssh",
        " scp",
        " transfer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "79b3561cd6afa959e9dd522af12acc4f803e8bab1bd0e383bffc5211721c5fcb",
                "md5": "8acf4d178ba59b28ac93aa25f7c10429",
                "sha256": "9e7f721e5ac563c33eb0831d0f949c6342f1c28c3bdc3b02f39d77b5ea20df7e"
            },
            "downloads": -1,
            "filename": "scp-0.15.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8acf4d178ba59b28ac93aa25f7c10429",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 8753,
            "upload_time": "2024-05-23T21:37:46",
            "upload_time_iso_8601": "2024-05-23T21:37:46.226793Z",
            "url": "https://files.pythonhosted.org/packages/79/b3/561cd6afa959e9dd522af12acc4f803e8bab1bd0e383bffc5211721c5fcb/scp-0.15.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d61cd213e1c6651d0bd37636b21b1ba9b895f276e8057f882c9f944931e4f002",
                "md5": "54c0e3b6cc52620ce3a81362fa8bb29d",
                "sha256": "f1b22e9932123ccf17eebf19e0953c6e9148f589f93d91b872941a696305c83f"
            },
            "downloads": -1,
            "filename": "scp-0.15.0.tar.gz",
            "has_sig": false,
            "md5_digest": "54c0e3b6cc52620ce3a81362fa8bb29d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13905,
            "upload_time": "2024-05-23T21:37:41",
            "upload_time_iso_8601": "2024-05-23T21:37:41.835352Z",
            "url": "https://files.pythonhosted.org/packages/d6/1c/d213e1c6651d0bd37636b21b1ba9b895f276e8057f882c9f944931e4f002/scp-0.15.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-23 21:37:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jbardin",
    "github_project": "scp.py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "scp"
}
        
Elapsed time: 0.23487s