You miss imports for your function (I believe it is somewhere in your code, but not in the posted snippedsnippet):
from collections import defaultdict import os Creation of files variable inside of the recursive function looks a bit weird from my non-Python point of view, but it has its advantages as you optional arguments can be skipped (scan different directory, append results to existing list of files), which seems to be a good design.
I can criticize the function naming. recursive_ftp does not explain what does the function do. It is recursive (but it does not add much value) and it is not ftp. I might think about list_sftp?