Issue
I was wondering if there's a way to send files using SFTP to a remote machine through a jump server. As you can see in the image below first it's needed an SSH connection and after that an SFTP connection.
My main problem here comes after the SSH connection, my workspace has changed and I cannot retrieve the necessary files to execute the SFTP successfully. I've tried the following code:
ssh [email protected] 'echo "put /source/files /remote/files" | sftp -v [email protected]'
But it does not work.
I've tried to execute a simple command like pwd
using the SFTP connection and it works so I think the problem here is how the workspace change.
There would probably be an easier solution but I cannot use SSH on the jump server-remote machine connection and I cannot store the local files in the jump server to send them later to the remote machine.
Solution
If you have a recent OpenSSH (at least 8.0) locally, you can use the -J
(jump) switch:
sftp -J [email protected] [email protected]
With older version (but at least 7.3), you can use ProxyJump
directive:
sftp -o [email protected] [email protected]
There are other options like ProxyCommand
or port forwarding, which you can use on even older versions of OpenSSH. These are covered in Does OpenSSH support multihop login?
Answered By - Martin Prikryl Answer Checked By - Terry (WPSolving Volunteer)