I want to read file extended attributes using com.jcraft.JSch 0.1.55 (the file is on SFTP server). I know that class SftpATTR
actually does have a method
public String[] getExtended()
but in my case it returns null.
I see that in this code
static SftpATTRS getATTR(Buffer buf){ SftpATTRS attr=new SftpATTRS(); attr.flags=buf.getInt(); if((attr.flags&SSH_FILEXFER_ATTR_SIZE)!=0){ attr.size=buf.getLong(); } if((attr.flags&SSH_FILEXFER_ATTR_UIDGID)!=0){ attr.uid=buf.getInt(); attr.gid=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0){ attr.permissions=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0){ attr.atime=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_ACMODTIME)!=0){ attr.mtime=buf.getInt(); } if((attr.flags&SSH_FILEXFER_ATTR_EXTENDED)!=0){ int count=buf.getInt(); if(count>0){ attr.extended=new String[count*2]; for(int i=0; i<count; i++){ attr.extended[i*2]=Util.byte2str(buf.getString()); attr.extended[i*2+1]=Util.byte2str(buf.getString()); } } } return attr; }
the last if-statement is responsible for reading extended attributes but it seems to me that it always evaluates to false, because
int flags=0;
and
public static final int SSH_FILEXFER_ATTR_EXTENDED= 0x80000000;
I cannot change the flags directly because it’s setter doesn’t have a public modifier.
Is there another way to change the flags or read the extended attributes somehow?
Advertisement
Answer
You seem to assume that the SFTP “extended attributes” are “file system extended attributes”.
They are not.
SFTP “extended attributes” is an extension mechanism, by which an SFTP server can provide or set additional attributes about the files, which are not part of the standard SFTP file attributes.
They indeed can theoretically be mapped to file system extended attributes. But actually most SFTP servers, and particularly the most widespread OpenSSH, do not support any SFTP extended attributes at all, let alone file system extended attributes. See also Setting the extended file attributes using SSH.NET SftpClient.