scp


Namescp JSON
Version 0.14.5 PyPI version JSON
download
home_pagehttps://github.com/jbardin/scp.py
Summaryscp module for paramiko
upload_time2023-01-30 19:31:33
maintainerRemi Rampin
docs_urlNone
authorJames Bardin
requires_python
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": "",
    "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/b6/50/277f788967eed7aa2cbb669ff91dff90d2232bfda95577515a783bbccf73/scp-0.14.5.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\n\n",
    "bugtrack_url": null,
    "license": "LGPL-2.1-or-later",
    "summary": "scp module for paramiko",
    "version": "0.14.5",
    "split_keywords": [
        "paramiko",
        "ssh",
        "scp",
        "transfer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f044bcc504e6c2fdcfee7d74a6d14a49db0f129baf2cfa19f61148f333e96b9",
                "md5": "49c3c9cb63ca5dc015958932f7b266b7",
                "sha256": "d224535dd8ed00294f52b0e0e18fde7a6fb7a3d06b97ede9e3f750fa7bf75c09"
            },
            "downloads": -1,
            "filename": "scp-0.14.5-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "49c3c9cb63ca5dc015958932f7b266b7",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 8653,
            "upload_time": "2023-01-30T19:31:39",
            "upload_time_iso_8601": "2023-01-30T19:31:39.134308Z",
            "url": "https://files.pythonhosted.org/packages/7f/04/4bcc504e6c2fdcfee7d74a6d14a49db0f129baf2cfa19f61148f333e96b9/scp-0.14.5-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b650277f788967eed7aa2cbb669ff91dff90d2232bfda95577515a783bbccf73",
                "md5": "b7465344048ddbc0f6a7d7fb649105ea",
                "sha256": "64f0015899b3d212cb8088e7d40ebaf0686889ff0e243d5c1242efe8b50f053e"
            },
            "downloads": -1,
            "filename": "scp-0.14.5.tar.gz",
            "has_sig": false,
            "md5_digest": "b7465344048ddbc0f6a7d7fb649105ea",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12559,
            "upload_time": "2023-01-30T19:31:33",
            "upload_time_iso_8601": "2023-01-30T19:31:33.956633Z",
            "url": "https://files.pythonhosted.org/packages/b6/50/277f788967eed7aa2cbb669ff91dff90d2232bfda95577515a783bbccf73/scp-0.14.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-30 19:31:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "jbardin",
    "github_project": "scp.py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "scp"
}
        
Elapsed time: 0.05232s