from stat import S_ISDIR


def list_remote_files(con, directory):
	"""
	List the files and folders in a remote directory using an active SFTPClient from Paramiko
	:param con: SFTPClient, an active connection to an SFTP server
	:param directory: string, the directory to search
	:return: (generator, generator), the files and directories as separate generators
	"""

	print(directory)
	all_files = [file for file in con.listdir_attr(directory)]

	files = []
	dirs = []

	for file in all_files:
		if S_ISDIR(file.st_mode):
			file.path = directory + f'/{file.filename}'  # ad-hoc add the remote filepath since Paramiko ignores this?!
			dirs.append(file)
		else:
			file.path = directory + f'/{file.filename}'  # ad-hoc add the remote filepath since Paramiko ignores this?!
			files.append(file)

	files = (file for file in files)
	dirs = (dir for dir in dirs)

	return (files, dirs)