I just started using pysftp Python, and I am confused how to call it walktree function.
I found code (found at http://pydoc.net/Python/pysftp/0.2.8/pysftp/ ) that helped me better understand what form my parameters should take
def walktree(self, remotepath, fcallback, dcallback, ucallback, recurse=True): '''recursively descend, depth first, the directory tree rooted at remotepath, calling discreet callback functions for each regular file, directory and unknown file type. :param str remotepath: root of remote directory to descend, use '.' to start at :attr:`.pwd` :param callable fcallback: callback function to invoke for a regular file. (form: ``func(str)``) :param callable dcallback: callback function to invoke for a directory. (form: ``func(str)``) :param callable ucallback: callback function to invoke for an unknown file type. (form: ``func(str)``) :param bool recurse: *Default: True* - should it recurse :returns: None
But I'm still confused about what exactly is meant by the “callback function” for a regular file, for a directory, and for an unknown file type.
I also looked at the official documentation: https://media.readthedocs.org/pdf/pysftp/latest/pysftp.pdf
but all he tells me about the walktree() function is this:
It is a powerful method that can recursively (by default) navigate through a remote directory structure and call user-provided callback functions for each file, directory, or unknown object it encounters. It is used in the get_x pysftp methods and your own bets can be used with great effect. Each callback is provided with an organization path. (form: func(str) )
which I felt did not give me much information on how to properly call it.
If someone can provide an example of the correct work with this function and an explanation of why you pass the arguments you have chosen, we will be very grateful!
source share