I contact an SFTP
server and show files based on the modified timestamp.
Currently, it is done using something like:
files = os.listdir(SFTP)
- Loop over
files
and get the timestamp usingos.stat
. - Sort the final list in Python.
This looping in Step 2 is very costly when the SFTP is on a different server because it has to make a network call from the server to the SFTP for each and every file.
Is there a way to get both the file and modified time using os.listdir
or a similar API?
I am using a Windows back-end and the SFTP connection usually is done using the win32wnet.WNetAddConnection2 package. A generic solution would be helpful, if not a specific solution should be fine too.