Python SCPClient 复制进度检查

Nei*_*eil 3 python python-2.x

我是 SCPClient 模块的新手

我有复制样本

 with SCPClient(ssh.get_transport()) as scp:
    scp.put(source, destination)
Run Code Online (Sandbox Code Playgroud)

这段代码运行良好。

不过,由于我要复制几个大文件,复制进度需要时间,一味地等待完成并不是很好的用户体验。

无论如何,我可以监控它复制了多少吗?并获取复制成功与否的结果?

SCPClient 有官方文档可以阅读吗?

eag*_*gle 7

你看过Github 页面吗?他们提供了如何执行此操作的示例:

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()
Run Code Online (Sandbox Code Playgroud)