Multiple file support with scp
Paramiko doesn't provide a scp implementation, so I've been using my own for a while. http://blogs.sun.com/janp/entry/how_the_scp_protocol_works (link now unfortunately dead) provides good documentation about the scp protocol, but it missed out on one detail I needed -- how to send more than one file in a given session. In the end I implemented a simple scp logger to see what the protocol was doing during the copying of files. My logger said this: >>> New command invocation: /usr/bin/scp -d -t /tmp O: \0 I: C0644 21 a\n O: \0 I: file a file a file a\n\0 O: \0 I: C0644 21 b\n O: \0 I: file b file b file b\n\0 O: \0 >>>stdin closed >>> stdout closed >>> stderr closed It turns out its important to wait for those zeros by the way. So, here's my implementation of the protocol to send more than one file. Turning this into paramiko code is left as an exercise for the reader. #!/usr/bin/python import fcntl import os import select import string import subprocess import sys import traceback def printable(s): out = '' for c in s: if c == '\n': out += '\\n' elif c in string.printable: out += c else: out…