I'd like to get a remote file with SFTP, but choosing stdout as the local destination. I tried the obvious code below, but it failed:
echo 'get <Remote file> /dev/stdout' | sftp <User>@<Host>:
sftp> <Remote file> /dev/stdout
Fetching <Remote file> to /dev/stdout
<Remote file> 100% 28KB 57.6KB/s 00:00
ftruncate "/dev/stdout": Invalid argument
Couldn't write to "/dev/stdout": Illegal seek
The reason for that is that I want to download /etc/passwd and /etc/group to find numeric uids/gids for later chown and chgrp commands, in order to solve this problem. But it would be nicer if I could download such files to a variable, instead of a temporary local file.
A possibility would be to create a local named pipe, and save remote file to it, but I'd like to find a less complicated solution. An alternative would be an additional SSH session to get such data but, since we use timed tokens (TOTP), that would mean additional 30s per remote host...
SCP is forbidden in our network so, unfortunately, it's not an option.
Can SFTP get "save" to stdout?
Thanks!