I have just started using Python's pysftp and I am confused as how to call it's walktree
function.
I found some 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 am still confused on what exactly is meant by "callback function to invoke for a regular file, for a directory, and for an unknown file type.
I have also looked through the official documentation: https://media.readthedocs.org/pdf/pysftp/latest/pysftp.pdf
but all it tells me about the walktree()
function is that:
Is a powerful method that can recursively (default) walk a remote directory structure and calls a user-supplied callback functions for each file, directory or unknown entity it encounters. It is used in the
get_x
methods of pysftp and can be used with great effect to do your own bidding. Each callback is supplied the pathname of the entity. (form:func(str)
)
which I felt did not give me much information on how to call it properly.
If someone could provide an example of calling this function correctly and an explanation of why you are passing your chosen arguments, it would be greatly appreciated!