pkg / sftp

SFTP support for the go.crypto/ssh package
BSD 2-Clause "Simplified" License
1.5k stars 379 forks source link

Get file's username, groupname and another metadata #530

Closed alexey-sderzhikov closed 1 year ago

alexey-sderzhikov commented 1 year ago

Hi!

I need to get file's username and groupname with sftp, how i can do this? I found interface with useful methods for my goals:

type NameLookupFileLister interface {
    FileLister
    LookupUserName(string)
    LookupGroupName(string)
}

But i couldnt find any struct which implements this interface. How i need handle with this interface, or exist another ways to get file's username and groupname? Thanks for answers!

puellanivis commented 1 year ago

Unfortunately, I don’t think there is any way to lookup usernames and groupnames from the remote service. 🤔 You’re going to have to go off of the longname information in this case. But I’m not sure we surface that information up.

We’d like to be able to provide more of this data, but we really have rework a lot of the way the package works. We started some of that work with the internal/ssh/filexfer/ package, but I haven’t managed to complete even the client update. But in some ways, we almost need a new API entirely, so…

The interface you’re referencing is how one can define a way for a RequestServer to provide usernames and groupnames for clients when it’s generating the longname field of the SSH_FXP_NAME_ATTR without having to use the system’s username/groupname mappings.

alexey-sderzhikov commented 1 year ago

Thanks for your answer!

Okey, maybe i can call a shell command via ssh to find out metadata which i need with your package?

puellanivis commented 1 year ago

I would expect you could download the /etc/passwd file which would provide a mapping for you. But you’d have to self-decode it all.

alexey-sderzhikov commented 1 year ago

Yeah, i can find username it this way! But /etc/passwd consist only username info, how i can find groupname?

puellanivis commented 1 year ago

For groupnames those are in /etc/groups

alexey-sderzhikov commented 1 year ago

Thanks for your help. Can i help with features which we are talked above?

puellanivis commented 1 year ago

I’m not sure there is a generic sort of way to work around this stuff. So, I appreciate the offer, but I think this is a problem which we must fundamentally leave to the reader.