Generally, when we work in a secure environment we do have bastion host to connect application/DB server.
So when using Windows we can copy the file to a desktop from a remote server using the very nice tool called WinSCP. But on Mac, if we want to do it quickly without tool we can do it using below commands.
ssh -L <your_machine_free_port>:<remote_server_ip>:22 <bastion_server_user>@<bastion_server_ip> cat -
<your_machine_free_port> – Select any free port between 1024 and 32768
<remote_server_ip> – Server from where the file has to be copied
<bastion_server_user> – User name for bastion server
<bastion_server_ip> – Bastion server IP/DNS
“cat -” – To keep the connection
2. Copy (scp) a file
scp -i <ssh_key_if_any> -P <your_machine_free_port> <remote_server_user>@127.0.0.1:/file/path/to/copy .
If remote server needs an ssh key to connect, then pass the key with “-i” option or just ignore it.