I am trying to make a SFTP script to go through a directory and get all the files in it, inside this directory there are subdirectories that I would like to exclude. However when I use the stat.S_ISREG
function it gives an error of
OverflowError: mode out of range
From what I have read it seems like an error that Paramiko has with the handling of the bits that the server returns. Is there a way to solve this error, or some other way to differentiate files from folders based on the st_mode
? I was thinking of validating if the st_mode
is greater than 34000
exclude it and take it as a folder but I don't know if it is correct.
The code is the following:
client_ssh = paramiko.SSHClient()
client_ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client_ssh.connect(host,username=user,password=pwd)
sftp_client = client_ssh.open_sftp()
df_file_info_sftp = pd.DataFrame([attr.__dict__ for attr in sftp_client.listdir_attr(directorio_remoto)]).sort_values("st_mtime", ascending=False)
for row in df_file_info_sftp.itertuples():
print (row.filename)
if stat.S_ISDIR(row.st_mode):
print('Carpeta:')
if stat.S_ISREG(row.st_mode):
print('Archivo:' + row.filename)
sftp_client.close
client_ssh.close
The error is:
From what I have read, it seems to be an error that Paramiko has with the handling of the bits returned by the server (apparently there are more than 16 and that is why the error)