Yes and no. Shells (both local and SSH connections) do stack, but the remote shell started via SSH has no access to the locally running client. There is no back-tunnel for file transfer (there is one for ssh-agent but that's all).
You may be able to scp/sftp from the remote server back into the local computer, but it would act as a fully independent connection (yet another new layer in the stack) – it would know nothing about what "current folder" you were in.
So because the only method is a new SSH connection, obviously this needs your local computer to have an SSH server (sshd) running to begin with. (Fortunately, unlike nc, the sshd only needs to be set up once and left running forever.)
If your computer has a public IP address, the next step is to just SSH back from the Ubuntu system to your own IP address (as can be found in $SSH_CONNECTION). If both the client and the server have IPv6, that can be used.
Most PCs don't have a public IP address, so the alternative is to use SSH's -R
"remote TCP forwarding" feature to establish a back-channel – note that in this case it's still a brand new SSH login into your computer, it still doesn't know anything about the "parent" shell:
MyMac$ pwd
/Users/Fred/Documents/This/That
MyMac$ ssh -R 12345:localhost:22 ubuntu.example.com
ubuntu$ ssh -p 12345 localhost
MyMac$ pwd
/Users/Fred
MyMac$ exit
ubuntu$ scp -o Port=12345 file.json localhost:Documents/
In this example 12345 is a random port number that'll start accepting connections on the server, which will be carried to sshd on your local computer's port 22.
Note: In this example the -R option is specified before connecting, but if you happen to need it retroactively, you can just open a second connection (this time with -R) and the tunnel will be available globally. It is not limited to that particular shell/connection.
(Alternatively the keys Enter
~
C
should pop up an interactive prompt which accepts "-R 123..." as input and establishes the forwarding.)
Personally, I would recommend just SFTP'ing directly to the remote machine. Then you can navigate to the file using somewhat regular 'cd' and 'ls', then retrieve files using 'get'.
The default OpenSSH sftp
client isn't great but works fine; lftp is one of the better alternatives.
the lame way to do what I say is, just cat the file on screen. Then you effectively have it on the local machine: copy and paste to a file :) ( It occurs to me, one could write a custom version of a Terminal app that has this feature: it would understand when you type cat f.txt > LOCAL/f.tx it would actually just capture the result and save it to a text file!!! Heh! ) – Fattie 6 hours ago
Yes, some terminals support this – it's actually a feature that comes from the dial-up system and BBS days, and is called ZMODEM or XMODEM.
To receive a file via ZMODEM, you first make sure the local terminal has the file transfer feature enabled (I think it's present at least in the GNU Screen multiplexer, although very rarely in modern terminals), then run sz <file>
on the remote server and you should see the file pop up locally.
It seems someone has written integration scripts for Zmodem in iTerm2, too.