12

I'm in an SFTP session and navigated to a deep directory. I did ls -l, saw a small file, and want to just read it. I would prefer to do it while I'm still in SFTP, rather than starting up a new terminal, doing SSH, navigating to that deep directory, and then reading it, then going back to SFTP to continue.

Is there a way to do that?

SFTP has no cat command.

I tried get file -, hoping it would treat - as stdout, but that just creates a file called "-".

I tried get file /dev/stdout, but that results in:

sftp> get file /dev/stdout Fetching /home/username/file to /dev/stdout /home/username/file 100% 506 9.0KB/s 00:00 ftruncate "/dev/stdout": Invalid argument Couldn't write to "/dev/stdout": Illegal seek 

Another way might be get file /tmp/file, come out of SFTP, read /tmp/file, delete /tmp/file, and get back into SFTP, but that's equally as tedious. Is there an easy way?

2
  • 1
    lftp can do this easily. It's a matter of client's features. Commented Nov 5, 2020 at 16:20
  • 1
    perhaps sshfs would help? (search for sshfs here, or unix.stackexchange.com/a/178255/117549) Commented Nov 5, 2020 at 16:36

2 Answers 2

16

Having cat in sftp would mean that the contents of the file will still have to travel through the network, to your local machine, to be displayed for your eyes, which is basically, you get ther file. You don't have to "come out of SFTP": sftp can run commands locally using !.

So, you can do:

sftp> lcd /tmp sftp> get file sftp> !cat file 

Changing to /tmp ensures that get file doesn’t overwrite file in your current (local) directory; if that’s not an issue you can skip it.

0
3

You cannot execute cat via sftp because it is designed specifically for file transfer. You can check "man sftp" to find the list of commands that you can use while in the interactive shell.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.