asyncssh
asyncssh copied to clipboard
Progress handler for a session
Hello,
Is it possible to have a progress handler for the execution of a command?
Instead of getting the entire file (which is rather big) over sftp, I perform a "cat [filename] | grep ..." using connection.run (or sometimes even I have to open a session with a specific user due to file permits), so it filters out the information I need and reduces the size being transferred. I would like to know if there is a way to get the progress of the bytes being transferred after executing a command.
Thanks
I'm not really sure how that would work. In this case, the AsyncSSH client would have no idea what kind of "total bytes" value to report. At best, all it could do is report on the number of bytes it has read on the channel, without knowing when the command will finish or what the total size is. If you grep for a pattern that doesn't match, you basically wouldn't see any output at all until it got to the end with no bytes read, and so you'd no status report until then.
Note: If there's a chance you might get a large amount of output, using connection.run() is not recommended. You should probably use something like connection.create_process(), and then you'd be able to loop while reading from stdout, processing data sent by the server as it came in rather than trying to buffer up the entire output and return it at the end. You could then track yourself how much total output has been read as you go, and use that to report status.
While a simplified version of a progress handler could be called from run(), about all it could report is the total number of bytes sent on stdin and bytes received on stdout & stderr. Since this is easy to do with create_process(), though, I'm thinking it might be best to leave that to the application.
Closing due to inactivity. Feel free to reopen this or open a new issue if you need anything else.