[paramiko] scp [ again :) ]

James Bardin jbardin at bu.edu
Thu Feb 14 12:32:33 PST 2008


Hi Robey,

I know there's been numerous questions about scp, so here's a module 
that can plug right in paramiko if you like it.

The SCPClient takes an open transport, and gives you an object that can 
send files an directories. The only scp feature I didn't implement was 
the bandwidth limit. This has only been tested with openssh scp (scp1). 
Scp2 is just a wrapper for sftp, which we already have. If sftp didn't 
run at 30% the speed of scp (at least with openssh), I wouldn't have a 
need for this.

For those progressbar lovers, get_progress() gives you an object with a 
tuple of (bytes sent, file size) that's updated during file transfers. 
Though, you need to run the client in a separate thread if you want be 
able to do something with the progress during a transfer.

Quick examples:
#####
from paramiko import SSHClient, SCPClient, MissingHostKeyPolicy
client = SSHClient()
...
trans = client.get_transport()

# this is all it takes to send a file!
scp = SCPClient(trans)
scp.send_file('aFile.txt')

# renaming on the receiving side
scp.send_file('/path/to/testfile', 'renamed.testfile')
scp.close()

# with recursive, you must to specify the local path,
# and the filename
scp = SCPClient(trans, recursive=1, preserve_times=1)
scp.push_dir('paramiko', 'paramiko')
scp.push_dir('paramiko/dirname', 'dirname')
scp.send_file('paramiko/dirname/testfile', 'testfile')
scp.pop_dir()
scp.send_file('paramiko/__init__.py', '__init__.py')
scp.close()
client.close()
####

Thanks,
-jim

-------------- next part --------------
A non-text attachment was scrubbed...
Name: scp.py
Type: text/x-python
Size: 4994 bytes
Desc: not available
Url : http://www.lag.net/pipermail/paramiko/attachments/20080214/22aeda8c/attachment.py 


More information about the paramiko mailing list