Closed sabatini0035 closed 3 months ago
I think this is way more code than I'm willing to add for this feature. It's fine if it is built in the protocol, but this is a lot, and probably something that should be at a lower layer (e.g. socket).
Understood. I needed the feature for a work project, so I thought I would share. Just be aware that the bandwidth limit code in your master branch does not work, and will throw an error if used.
I'm surprised to hear this because there are tests? 34c25368
I made the lower-layer thing I mentioned: socket-throttle
Here's an example with scp.py: examples/paramiko_scp.py
My mistake, I was focused on my use case, which was sending files to a Cisco IOS XE switch. Their SCP server does not support the -l flag. Thanks for the link to the socket throttle. I will see if it works for my scenario.
The bandwidth limit feature currently on the master branch did not work when used. It is adding the -l flag to the scp command which is part of OpenSSH's implementation, not the actual scp protocol. This branch adds the bandwidth limit (limit_bw) both to the SCPClient and to the "put" and "get" commands. If both limits are provided, the limit provided in the "put" or "get" command will be used, otherwise, the limit provided in the SCPClient will be used. If neither is provided, the file transfer will not use a limit.
The bandwidth limit works by capturing the time before each send/recv, calculates how long the transfer should take with the limit, and waits until the elapsed time reaches the limit before continuing on to the next send/recv.