I'm automating file transfer via SFTP and got stuck when changing file ownership in the remote host. The problem is that SFTP's chown and chgrp commands only accept numeric uids/gids, which are not known beforehand. The expected scenario for my automation is for the user to inform files destinations and string usernames and groupnames.
Is there a way to query the numeric uid/gid from the string user/groupname in the remote host through the SFTP session?
An easy workaround would be to open an additional SSH session and use regular shell's chown and chgrp commands. But the company I work in uses timed tokens for authentication and, in short, an additional session means additional 30 seconds per host, a non-starter for batch installations.
A harder one would be to ls -l directories, maybe files, to find one with the needed credentials, then ls -n to get the numeric version. But this has the risks of taking too long, findind no suitable directories/files or even getting stuck if a directory has too much files for ls to work...