Python Scpclient Copy Progress Check
I'm new on SCPClient Module I have got copy samples as with SCPClient(ssh.get_transport()) as scp: scp.put(source, destination) This code works well. However, since I'm copy
Solution 1:
Did you look at the Github page? They provide an example of how to do this:
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 filedefprogress(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)
scp.put('test.txt', '~/test.txt')
# Should now be printing the current progress of your put function.
scp.close()
Solution 2:
As Eagle answers, they are good to print out progress. However, the frequency of printing is too high, it will consume a lot resources.
To control the print frequency, we need override _send_file or _send_files function
def_send_files(self, files):
...
buff_size = self.buff_size
chan = self.channel
# Add time control
time_cursor=datetime.datetime.now()
while file_pos < size:
chan.sendall(file_hdl.read(buff_size))
file_pos = file_hdl.tell()
now=datetime.datetime.now()
# Status check every one secifself._progress and (now-time_cursor).seconds>1:
self._progress(basename, size, file_pos)
time_cursor=now
chan.sendall('\x00')
file_hdl.close()
self._recv_confirm()
Post a Comment for "Python Scpclient Copy Progress Check"