How to see (log) file transfer progress using paramiko?

user1071501 picture user1071501 · Nov 29, 2011 · Viewed 8.4k times · Source

I'm using Paramiko's SFTPClient to transfer file between hosts. I want my script to print the file transfer progress similar to the output seen using scp.

$ scp my_file user@host

user@host password: 

my_file                          100%  816KB 815.8KB/s   00:00

$

Any idea?

Thanks in advance

Answer

Spencer Rathbun picture Spencer Rathbun · Nov 29, 2011

Use the optional callback parameter of the put function. Something like this:

def printTotals(transferred, toBeTransferred):
    print "Transferred: {0}\tOut of: {1}".format(transferred, toBeTransferred)

sftp.put("myfile","myRemoteFile",callback=printTotals)