4

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
8

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", as sftp has !command.

So, you can do:

sftp> get file
sftp> !cat file
1
  • 1
    Useful to know. I guess you might also want do lcd /tmp/ or similar before downloading, so the file goes into your own /tmp folder rather than littering whatever directory you ran sftp from.
    – mwfearnley
    Jan 30 at 14:36
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.