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
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()
$ md5sum test.txt test2.txt
fc264c65fb17b7db5237cf7ce1780769 test.txt
fc264c65fb17b7db5237cf7ce1780769 test2.txt
Using ‘with’ keyword
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')
$ 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:
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.
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()
Metadata
Release files for scp 0.16.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scp-0.16.2.tar.gz | 13.2 kB | Without provenance | Details for scp-0.16.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scp-0.16.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for scp-0.16.2-py2.py3-none-any.whl |
Total release size: 22.2 kB
Release files / scp-0.16.2.tar.gz
| Download URL | scp-0.16.2.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d049f9aa77db4042c44b922cecabe97ef0716fb334a95701d68d1c7991684fc2
|
|
BLAKE2b-256 checksum How to use checksums |
38c34d0230664b7c505ba2fa7bf9fe4bee83f6f1fa195e865ad7f92b12917e59
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / scp-0.16.2-py2.py3-none-any.whl
| Download URL | scp-0.16.2-py2.py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
98d2e9ecdbe09e6bd41c22d6b69a93f203589a6590624685373e81f8bfdc60fd
|
|
BLAKE2b-256 checksum How to use checksums |
d9e95bcfe3b31ba522adb5983d718121e3c34879981dd39bdb7b5dd1ced5ecbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for scp 0.16.2
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.