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)
scp.put('test.txt', '~/test.txt')
# Should now be printing the current progress of your put function.
scp.close()
你看了Github page?它们提供了一个如何执行此操作的示例:
正如老鹰所说,他们很好地打印出进展情况。但是,打印频率太高,会消耗大量的资源。在
要控制打印频率,我们需要重写“发送文件”或“发送文件”功能
相关问题 更多 >
编程相关推荐