I'm connecting to an SFTP server (NTFS) and trying to pick up all the files that are regular files (in my case, they're json files for now, but they could be anything else). This is the relevant snippet of code:
import stat
import paramiko
# more code here
for file in sftp_client.listdir_attr(curr_path):
if stat.S_ISREG(file.st_mode):
# do something
My problem here is that every file comes back as False when I check for S_ISREG. The file is just a plain json so it should be marked as a regular file.
I suspect the issue is that S_ISREG which checks the inode of the file is a very Unix concept, whereas the server is Windows based. Am I right to suspect this? That I can't use S_ISREG or anything to do with the inode because the Windows NTFS file doesn't have an inode value?
How else might I go about checking if these files are regular or not?
Yes, it's possible that your Windows SFTP server does not set the S_IFREG
flag.
I'd instead test if the entry is not a folder:
if not stat.S_ISDIR(file.st_mode):
(you might want to test also stat.S_ISLNK
)