I’ve not used the sftp module to advise, but one way could be to create a check in your code for if you’ve reach 5000 records, create an identifier for that point, then change your query to exclude previously received records. (IE, date equal to or older than current records date then skip the result set until you get back to the record you left off on)
In other words, if it is over 5,000, then you will need to reduce your result list set size. I don’t have the api docs open atm to provide direct options, but hopefully this can help steer you the right way 🤷♂️