Netmiko SecureCopy Progressbar



我正在努力改进我的代码,并将进度条添加到file_transfer函数中。我想知道如何计算sent自变量?我在这里和GitHub上找到了这个答案,但我不知道如何将其与我提供的代码一起使用。

from os.path import getsize
from netmiko import ConnectHandler, file_transfer, progress_bar
router = {
"device_type": "cisco_ios",
"host": "sandbox-iosxe-latest-1.cisco.com",
"username": "developer",
"password": "C1sco12345",
"port": 22,
"verbose": True,
"conn_timeout": 12,
"fast_cli": False,
"session_log": "sandbox-iosxe-latest-1.cisco.com.log",
}
src_file = dest_file = input("Name of file to copy: ")
with ConnectHandler(**router) as net_connect:
scp = net_connect.send_config_set(config_commands=["ip scp server enable"])
transfer = file_transfer(
net_connect,
source_file=src_file,
dest_file=dest_file,
file_system="flash:",
direction="put",
overwrite_file=True,
socket_timeout=100.0,
progress=progress_bar(
filename=src_file,
size=getsize(src_file),
sent=sent,  # How to calculate? What should be placed here?
),
)

应该只是progress=progress_barprogress4=progress_bar。您只需要提供一个以某种方式构建的可调用函数(并且您正在使用Netmiko提供的progress_bar函数,所以这应该很好(。

下面是一个使用它的file_transfer示例:

ssh_conn = ConnectHandler(**cisco)
transfer_dict = file_transfer(
ssh_conn,
source_file=source_file,
dest_file=dest_file,
file_system=file_system,
direction=direction,
# Force an overwrite of the file if it already exists
overwrite_file=True,
progress4=progress_bar,
)

相关内容

  • 没有找到相关文章

最新更新