scp module for paramiko
Project Links
Meta
Author: James Bardin
Maintainer: Remi Rampin
Classifiers
Development Status
- 5 - Production/Stable
Intended Audience
- Developers
License
- OSI Approved :: GNU Library or Lesser General Public License (LGPL)
Operating System
- OS Independent
Programming Language
- Python
- Python :: 2.6
- Python :: 2.7
- Python :: 3
Topic
- Internet
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()
0.16.1
Jul 29, 2026
0.16.0
Jul 13, 2026
0.15.0
May 23, 2024
0.14.5
Jan 30, 2023
0.14.4
Feb 23, 2022
0.14.3
Feb 15, 2022
0.14.2
Dec 15, 2021
0.14.1
Sep 10, 2021
0.14.0
Sep 07, 2021
0.13.6
Jul 09, 2021
0.13.5
Jun 28, 2021
0.13.4
Jun 08, 2021
0.13.3
Oct 26, 2020
0.13.2
Mar 20, 2019
0.13.1
Mar 11, 2019
0.13.0
Nov 12, 2018
0.12.1
Oct 12, 2018
0.12.0
Oct 09, 2018
0.11.0
May 05, 2018
0.10.2
May 15, 2015
0.10.1
May 15, 2015
0.10.0
May 07, 2015
0.9.0
Mar 04, 2015
0.8.0
Apr 14, 2014
0.7.2
Mar 28, 2014
0.7.1
Dec 30, 2013
0.7.0
Dec 02, 2013
0.6.2
Nov 22, 2013
0.6.1
Nov 20, 2013
0.6.0
Nov 13, 2013
0.5.1
Apr 08, 2013
0.9.0.macosx
Mar 04, 2015
0.8.0.macosx
Apr 14, 2014
0.7.2.macosx
Mar 28, 2014
0.7.1.macosx
Dec 30, 2013
0.7.0.macosx
Dec 02, 2013
0.6.2.macosx
Nov 22, 2013
0.6.1.macosx
Nov 20, 2013
0.6.0.macosx
Nov 13, 2013
0.5.1.macosx
Apr 08, 2013
Wheel compatibility matrix
Files in release
Extras:
None
Dependencies:
paramiko