import paramiko
from socket import error as socket_error
import os
server =[\'10.10.0.1\',\'10.10.0.2\']
path=\'/home/test/\'
for hostname in server:
try:
SFTPClient.listdir returns file names only, not a full path. So to use the filename in another API, you have to add a path:
for i in sftp.listdir(path):
info = sftp.stat(path + "/" + i)
print info.st_size
Though that's inefficient. Paramiko knows the size already, you are just throwing the information away by using SFTPClient.listdir
instead of SFTPClient.listdir_attr (listdir
calls listdir_attr
internally).
for i in sftp.listdir_attr(path):
print i.st_size