How to pipe a remote file to stdout over scp or sftp?

For people who can run scp, you can do this:

scp remotehost:/path/to/remote/file /dev/stdout

Curl can display the file the same way cat would. No need to delete the file since it simply displayed the output unless you tell it to do otherwise.

curl -u username:password sftp://hostname/path/to/file.txt

If you use public key authentication:

curl -u username: --key ~/.ssh/id_rsa --pubkey sftp://hostname/path/to/file.txt

If you use the default locations, then --key and --pubkey can be omitted:

curl -u username: sftp://hostname/path/to/file.txt

The user name can also be a part of the URL, so the final result looks very close to the ssh command:

curl sftp://username@hostname/path/to/file.txt

Tags:

Sftp

Ssh

Scp

Cat