Secure Copy with Progressbar
See original GitHub issueHello @ktbyers,
I am trying to improve my code and add the progressbar to the file_transfer
function. I was wondering how can I calculate the sent
argument? I found this answer on SOF and this demo on GitHub, but I can’t figure out how to use it with my provided code.
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?
),
)
Thanks a lot.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Progress bar for scp command - ssh - Ask Ubuntu
@fuero man scp : " -3 Copies between two remote hosts are transferred through the local host. Without this...
Read more >How to use the SCP command in Linux - BudgetVM
Short for Secure Copy, the SCP command copies files and ... option to suppress the progress bar as data is being copied to...
Read more >Advanced Copy - Shows Progress While Copying Files in Linux
Advanced-Copy is a command line program that is very much similar, ... Advanced Copy Command – Shows Progress Bar While Copying/Moving Files ...
Read more >c# - File Copy with Progress Bar - Stack Overflow
I wanted to continuously increment the value of the progress bar while copying, especially large files. What happens in this sample code is...
Read more >Progress bar in SCP transfers #938 - ktbyers/netmiko - GitHub
Any plans to add a progress bar to the SCP transfers? I ask because you're using the package, and he gives an example...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, nice…yeah, we should update Netmiko’s default progress bar to use “rich”.
Finally, I had the time to find a pretty method of printing the progress in terminal.
This is actually the same as in the scp.py README but using
print()
fromrich
instead ofsys.stdout.write()
to have a colored output in the terminal.The only drawback of using
end=" \r"
is that the print statement after theprogress_bar
print statement overwrites it.UPDATE:
A simple workaround to keep the progress bar print statement in the terminal and not to be overwritten by the next print statement is to prepend a
\n
to the latter.