I have a small utility that scans ftp server and does some analytics around available data. This code works fine for many servers but does not work for one particular server. I am sure the data is available on the server, lots of data, but it only lists the top folders and when goes inside of them just gets nothing.
Nothing fails, just empty data in the listdir_attr
I tried looking into the connection options that may influence this, but there doesn't seem any relevant. Has anyone faced similar issues?
import pysftp
import os
class Connector:
def __init__(self, host: str, user: str, password: str, port: int = 22, root: str = "."):
ops = pysftp.CnOpts()
ops.hostkeys = None
self.root = root
self.client = pysftp.Connection(host=host, username=user, password=password, port=port, cnopts=ops)
self.stats = list()
def __looper(self, folder):
for f in self.client.listdir_attr(folder):
f.attr["path"] = folder
f.attr["props"] = f.longname[:10]
self.stats.append(f)
if f.longname.startswith("d"):
self.__looper(os.path.join(folder, f.filename))
def build_stats(self):
self.__looper(self.root)
self.client.close()
return self.stats